-----------nginx同一域名下部署多个vue项目------------------------
1.目的
实现nginx服务端同一域名下部署多个vue项目。
2. 实例
pmobile项目: http://mobile.xxxx.cn/pmobile/xxx
emobile项目: http://mobile.xxxx.cn/emobile/xxx
- 修改 router/index.js
添加一行
(D:\xxx\workspace\gitlad-xxx-mobilebank-v2\src\router\index.js)pmobile:
base: 'pmobile'
(D:\xxx\workspace\xxx-enterprise-emobilebank\src\router\index.js)emobile:
base: 'emobile'
4.然后修改 config/index.js
(D:\xxx\workspace\gitlad-xxx-mobilebank-v2\config\index.js)Pmobile:
assetsPublicPath: '/pmobile/',
为了使开发模式下统一,
(D:\ynrrc\workspace\ynrcc-enterprise-emobilebank\config\index.js)emobile:
assetsPublicPath: '/emobile/',
为了使开发模式下统一,
5.nginx配置
server
{
listen 80;
root /usr/local/webserver/nginx/html/xxx/mobile-v2;
# listen [::]:80 ipv6only=on;
#listen [2001:470:c:13e0::2]:80;
listen [::]:80 ipv6only=on default_server;
server_name mobile.xxxxxx.com mobile.xxxxxx.cn localhost;
charset utf-8;
access_log on;
access_log logs/mobile.xxxx.access.log;
expires -1;
#location /
#{
#root /usr/local/webserver/nginx/html/xxx/mobile-v2;
# try_files $uri $uri/ /index.html;
#}
location /emobile{
try_files $uri $uri/ /emobile/index.html;
}
location /pmobile {
try_files $uri $uri/ /pmobile/index.html;
}
location /xxx
{
proxy_pass https://xxx.xxxx.com/xxx;
# TODO 一下配置是想直接定位到某一台后端服务
# proxy_pass https://xxxxx/xxx
proxy_set_header Host $host:$server_port;
proxy_set_header X-Forwarded-For $remote_addr; # HTTP的请求端真实的IP
proxy_set_header X-Forwarded-Proto $scheme; # 为了正确地识别实际用户发出的协议是 http 还是 https
}
error_page 404 /404.html;
# To allow POST on static pages
error_page 405 =200 $uri;
# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html
{
root html;
}
}