-----------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;
}
}
————————————————
版權聲明:本文為CSDN博主「N_years」的原創文章,遵循CC 4.0 BY-SA版權協議,轉載請附上原文出處鏈接及本聲明。
原文鏈接:https://blog.csdn.net/ly124100427/article/details/86604763