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

以 espace 和 mobile 项目为例
server {
   listen 8001;
   location / {
       root   /opt/espace; #示例 /root/lc/dist #注意:用‘/’
       index  index.html index.htm;
       try_files $uri $uri/ /index.html;  #解决子页面适配,刷新404问题
   }
}
server {
   listen 8002;
   location / {
       root   /opt/mobile; #示例 /root/lc/dist #注意:用‘/’
       index  index.html index.htm;
       try_files $uri $uri/ /index.html;  #解决子页面适配,刷新404问题
   }
}
upstream a.xxx.com{
    server 127.0.0.1:8081;
}
server {
    server_name a.xxx.com;
  	location /{
        proxy_pass http://a.xxx.com;
    }
    location /api/ {
        proxy_pass http://p.xxx.com/;
    }
    location /apis/ {
        proxy_pass http://egw.xxx.com/;
    }
    location ^~/espace/ {
        proxy_pass http://127.0.0.1:8001/;
    }
    location ^~/mobile/ {
        proxy_pass http://127.0.0.1:8002/;
    }
}

你可能感兴趣的:(nginx,vue)