域名子目录发布问题(nginx、vue-element-admin、uni-app)
- 说明
- Vue-Element-Admin 代码打包
- nginx配置:
- uni-app打包
说明
使用一个域名下子目录进行打包:
比如:
http://www.xxx.com/merchant 商户端代码
http://www.xxx.com/h5 移动端代码
http://www.xxx.com/api 接口地址
Vue-Element-Admin 代码打包
1, vue.config.js 中 配置:
publicPath: process.env.NODE_ENV === "production" ? "/merchant/" : "/merchant/",
2, router/index.js 中:
export default new Router({mode: 'history', // 去掉url中的#base: 'merchant', //这里需要加子目录名称scrollBehavior: () => ({y: 0}),routes: constantRoutes
})
nginx配置:
server{#SSL 默认访问端口号为 443#listen 443 ssl; listen 80;#请填写绑定证书的域名server_name www.xxx.com; #web商户端页面location /merchant {# root 和 alias 区别,自行百度alias /www/wwwroot/merchant;index index.html;try_files $uri $uri/ /merchant/index.html;}#h5移动端页面location /h5 {# root 和 alias 区别,自行百度alias /www/wwwroot/h5;index index.html;try_files $uri $uri/ /h5/index.html;} # HTTP反向代理相关配置开始 >>>location ~ /purge(/.*) {proxy_cache_purge cache_one $Host$request_uri$is_args$args;} #平台apilocation /api/ {# 这里是服务地址或者网关地址。proxy_pass http://127.0.0.1:8020/;proxy_set_header Host $Host:$server_port;proxy_set_header X-Real-IP $remote_addr;proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;proxy_set_header REMOTE-HOST $remote_addr; proxy_set_header X-Host $host:$server_port;proxy_set_header X-Scheme $scheme;proxy_connect_timeout 30s;proxy_read_timeout 86400s;proxy_send_timeout 30s;proxy_http_version 1.1;proxy_set_header Upgrade $http_upgrade;proxy_set_header Connection "upgrade";}# HTTP反向代理相关配置结束 <<<}
uni-app打包
发布配置文件:
"h5" : {"title" : "H5","router" : {"mode" : "history","base" : "/h5/"},"devServer" : {"https" : false},"domain" : "http://www.xxx.com/api"}