nginx-部署nginx刷新后页面404找不到

问题描述:

1.使用Nginx部署后,登录页面刷新一下就出来404、

2.配置完前端暴露的页面访问ip和端口号后,访问报404

server {
        listen       21060;
        server_name  localhost;
 
        location / {
            root   html/dist;
            index  index.html index.htm;
        }
        location /gateway/ {
             rewrite ^/gateway/(.*) /$1 break;
             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_set_header X-Forwarded-Proto $scheme;
             proxy_connect_timeout 5;
             proxy_pass http://x.x.x.x:port/;
    }

1.完善了try_files $uri $uri/ /dist/project/index.html,

指定了根目录下,详细的index。html访问路径

2.完善root html/dist/project属性;

我们的前端代码在dist内还有一层文件夹,难道是没找到吗,挺奇怪的

完善之后,nginx即可正常访问前端服务

猜你喜欢

转载自blog.csdn.net/qq_44691484/article/details/126354457