vue 部署tomcat 或则 nginx

本文介绍了Vue项目的部署,包含环境信息,如Java、npm、node、vue等版本。详细说明了部署到Tomcat和Nginx的步骤,部署到Tomcat要处理跨域问题,注意vue.config.js配置;部署到Nginx要注意接口格式、文件路径及nginx.conf修改,还提及常用命令和代理配置注意事项。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

环境信息

java -version   java version "1.8.0_201"

catalina   Using CATALINA_BASE:   "D:\install\apache-tomcat-9.0.21"

npm   -v 6.4.1

node -v   v10.15.3

vue -V   3.70

Stable version   nginx/Windows-1.16.0  pgp   nginx下载

 

部署到tomcat 

部署到tomcat需要后台处理跨域问题

vue.config.js

重点关注 :baseUrl: process.env.NODE_ENV === 'production' ?'/dist/' : '/',

module.exports = {
    // publicPath: './',
    baseUrl: process.env.NODE_ENV === 'production' ?
        '/dist/' :
        '/',
    outputDir: 'dist',
    assetsDir: 'static',
    lintOnSave: false,
    devServer: {
        open: true,
        host: "localhost",
        port: 8080,
        https: false,
        hotOnly: false,
        proxy: {
            '/api': {
                target: 'http://xx.xx.xx.xx:8888',
                // target: 'https://api.apiopen.top',
                changeOrigin: true,
                ws: true,
                pathRewrite: {
                    '^/api': ''
                }
            },
        }
    }

}

npm run build   出包dist

将 dist 文件夹拷贝到 D:\install\apache-tomcat-9.0.21\webapps\

startup.bat   访问 https://localhost/8080/dist.

如果页面空白请检查路由配置:mode:"history"改为mode:"hash"即是默认

 

部署到nginx

后台接口:http://192.168.3.XXX:8125/video/moreresult?resultID=" + imgUuid

注意xxx.vue的接口格式:this.$axios.get("/api" + "/video/moreresult?resultID=" + imgUuid)

将dist文件夹拷贝到 D:\install\xnginx-1.16.0\html\ (此路径每层不能已n开头,例如:nginx许改为xnginx,因为/n会进行转义 

修改 D:\install\xnginx-1.16.0\conf 目录下的nginx.conf

 server {
        listen       8007; #访问地址的端口
        server_name  localhost; #访问地址

        #charset koi8-r;

        #access_log  logs/host.access.log  main;

        location / {
            root   D:\install\xnginx-1.16.0\html; #dist路径
            index  index.html index.htm;
        }
		
		location /api/{
           proxy_pass http://192.168.3.XXX:8125/; #后台接口地址
        }

        #error_page  404              /404.html;
        .
        .
        .
        }

nginx 常用命令:启动命令 start nginx   关闭命令 nginx -s quit   重新启动命令 Nginx -s reload

访问 https://localhost/8007/dist

注意事项:nginx中配置proxy_pass时

location /api/ {

     proxy_pass http://192.168.3.XXX:8125/;

}

会被代理到 http://192.168.3.XXX:8125/video/moreresult?resultID=" + imgUuid

location /api/ {

    proxy_pass http://192.168.3.XXX:8125;

}

会被代理到 http://192.168.3.XXX:8125/api/video/moreresult?resultID=" + imgUuid

location /api/ {

    proxy_pass http://192.168.3.XXX:8125/demo/;

}

会被代理到 http://192.168.3.XXX:8125/demo/video/moreresult?resultID=" + imgUuid

location /api/ {

    proxy_pass http://192.168.3.XXX:8125/demo;

}

会被代理到 http://192.168.3.XXX:8125/demovideo/moreresult?resultID=" + imgUuid

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值