nginx同一域名下部署多个vue项目

-----------nginx同一域名下部署多个vue项目------------------------

1.目的

 

实现nginx服务端同一域名下部署多个vue项目。

 

2. 实例

 

pmobile项目: http://mobile.xxxx.cn/pmobile/xxx

 

emobile项目: http://mobile.xxxx.cn/emobile/xxx

 

  1. 修改 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;

  }

 

}

 

回答: 在nginx中,可以通过配置来实现一个端口部署多个vue项目。首先,在vue项目vue.config.js文件中,需要配置publicPath参数,以及路由中的base参数,用来指定项目的访问路径。\[1\]接下来,在nginx的配置文件nginx.conf中,需要添加对应的location路径,用来匹配请求路径,并将请求转发到对应的项目文件夹下。\[2\]在上传文件到服务器后,需要修改nginx.conf文件,将location路径指向对应的项目文件夹,并重启nginx服务。这样,就可以通过同一个端口访问不同的vue项目了。\[2\] #### 引用[.reference_title] - *1* [Nginx同一端口部署多个vue项目](https://blog.csdn.net/jacob20130/article/details/125368431)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^control_2,239^v3^insert_chatgpt"}} ] [.reference_item] - *2* [nginx一个端口部署多个vue项目](https://blog.csdn.net/qq_38255367/article/details/111661353)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^control_2,239^v3^insert_chatgpt"}} ] [.reference_item] - *3* [Nginx一个端口部署多个vue项目](https://blog.csdn.net/outman1023/article/details/117823009)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^control_2,239^v3^insert_chatgpt"}} ] [.reference_item] [ .reference_list ]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值