nginx反向代理二级目录 导致vue项目静态文件css js访问不到

时间:2025-04-23 22:33:35

2022年5月30日19:06:00

nginx vue项目配置

    server {
        listen 9888;
        server_name 127.0.0.1;

        error_log   /data/log/nginx/;
        access_log  /data/log/nginx/;

        root "/data/wwwroot/houtai";
        index ;
        charset utf-8;
        location / {
            autoindex  off;
            try_files $uri $uri/ /;
        }

nginx反向代理配置

这个主域名的二级目录反向代理过去

     location /houtai/ {
            proxy_set_header Host $host;
            proxy_set_header X-Real-IP $remote_addr;
            proxy_set_header X-Forwarded-For $remote_addr;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
            proxy_set_header Remote_addr $remote_addr;

            proxy_pass http://127.0.0.1:9888/;
        }

但是会造成js css 静态文件无法访问

vue 2.

publicPath: .NODE_ENV === 'production' ? '/houtai' : '/',

就可以了

可以在dist文件夹,文件 引用文件是否有 houtai 前缀