Saber打包部署到Nginx遇到问题(Nginx如何部署多个Saber项目)

Saber 未结 1 2971
huangyuxi
huangyuxi 剑童 2019-09-19 16:43

一、该问题的重现步骤是什么?

1. Nginx默认启动在80端口,saber 打包后,部署到Nginx的html/hyx

2. 访问 http://localhost/hyx, 一直显示正在加载资源,F12查看,加载的css,js等资源从html根目录加载


3. 修改Nginx配置文件,增加监听8000,其伺服目录为html/saber,配置api代理接口到https://saber.bladex.cn/api 访问 http://localhost:8000 页面访问成功,登录成功

配置如下:

    server {

        listen       8000;

        server_name  localhost;

        location / {

            root html/hyx;

            index index.html index.htm;

         }


        location ^~/api {

            proxy_set_header Host $host;

            proxy_set_header X-Real-IP $remote_addr;

            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

            proxy_buffering off;

            rewrite ^/api/(.*)$ /$1 break;

            proxy_pass https://saber.bladex.cn/api;

        }

    }

二、你期待的结果是什么?实际看到的又是什么?

       nginx只监听80端口,saber 打包后,部署到Nginx的html/hyx, 通过二级目录方式http://localhost/hyx 可以直接访问登录。

       但是http://localhost/hyx 仍然访问不了!


三、你正在使用的是什么产品,什么版本?在什么操作系统上?

       saber,在win7上打包编译,部署也是win7系统上,对接的后台是官方后台api,用于测试。




1条回答
  • 2019-09-20 10:40

     在文件vue.config.js 增加 publicPath: '' 即可,打包后随便部署nginx子目录。

    module.exports = {
    publicPath: '', //默认是'/'
      ......
    }

    参考 https://cli.vuejs.org/zh/config/#publicpath

    5 讨论(0)
提交回复