nginx反向代理过程中碰到的蜜汁问题

 

目的,将对本机80端口的访问代理到192.168.121.11

原配置:

server {
        listen       80;
        server_name  localhost;

        #charset koi8-r;

        access_log  logs/host.access.log  main;

        location = /index.html {
           root /mnt/app/Web;
           index index.html index.htm;
           add_header Cache-Control no-cache;

        }

        location ~* ^.+\/[^\/]+(?=\.)([^\/](?!(ini)))+$ {
            root   /mnt/app/Web;
            index  index.html index.htm;
            add_header Cache-Control no-cache;
        }
        
        location / {
           root   /mnt/app/Web/;
           index  index.html index.htm;
        }
        #代理        
        location  /head {
                #proxy_pass http://100.100.100.102/;
                proxy_pass http://192.168.121.11/;
        }

    }

但是发现这么做无法加载静态资源(js、css等),尝试新加端口代理,可以正常加载:

    server {
        listen       8000;
        server_name  head;

        location /head {
                #proxy_pass http://100.100.100.102/;
                                proxy_pass http://172.18.80.94/;
        }
    }

但由于业务需要,必须使用80端口。

找了很久找不到原因,后续终于在某篇文章找到了类似问题,改为如下配置后成功代理:

server {
        listen       80;
        server_name  localhost;

        #charset koi8-r;

        access_log  logs/host.access.log  main;

        location = /index.html {
           root /mnt/app/Web;
           index index.html index.htm;
           add_header Cache-Control no-cache;

        }

        location ~* ^.+\/[^\/]+(?=\.)([^\/](?!(ini)))+$ {
            root   /mnt/app/Web;
            index  index.html index.htm;
            add_header Cache-Control no-cache;
        }
        
        location / {
           root   /mnt/app/Web/;
           index  index.html index.htm;
        }
        #增加“^~”后生效        
        location ^~  /head {
                #proxy_pass http://100.100.100.102/;
                proxy_pass http://192.168.121.11/;
        }

    }

 不太能理解为什么8000端口直接就能生效的80端口就要加个^~才可以。。。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值