nginx反向代理出现了代理的端口号

nginx反向代理显示了代理的端口号

  • nginx反向代理配置文件
upstream mall {
     server 1.1.1.1:10261 weight=1;
}
server
{
    listen 80;
    server_name vinehootest.test.cn;

location / {
        proxy_pass http://mall;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header Via "nginx";
     }
}

问题

  • 输入网址vinehootest.test.cn可以正常访问
  • 但是输入vinehootest.test.cn/dist 却跳转到vinehootest.test.cn:10261/dist/
  • 一直没有想明白是什么原因, 最后发现是静态资源出现了问题
upstream mall {
     server 1.1.1.1:10261 weight=1;
}
server
{
    listen 80;
    server_name vinehootest.test.cn;

location / {
        proxy_pass http://mall;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header Via "nginx";
     }
}

#添加静态资源访问路径就正常访问了
       location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
        {
            proxy_pass http://mall;
        }

        location ~ .*\.(js|css)?$
        {
            proxy_pass http://mall;
        }

posted @ 2020-05-21 13:44  云丛  阅读(2397)  评论(1编辑  收藏  举报