美文网首页
nginx配置proxy_pass时url末尾带“/”与不带“/

nginx配置proxy_pass时url末尾带“/”与不带“/

作者: xueyueshuai | 来源:发表于2022-05-26 20:34 被阅读0次
    WechatIMG186.jpeg

    proxy_pass配置中url末尾带/时,
    nginx转发时,会将原uri去除location匹配表达式后的内容拼接在proxy_pass中url之后。

    测试地址:http://192.168.171.129/aaa/bbb.jsp
    
    场景一:
    location ^~ /aaa/ {
        proxy_pass http://192.168.171.129:8080/server/;
    }
    代理后实际访问地址:http://192.168.171.129:8080/server/bbb.jsp
    
    场景二:
    location ^~ /aaa {
        proxy_pass http://192.168.171.129:8080/server/;
    }
    代理后实际访问地址:http://192.168.171.129:8080/server//bbb.jsp
    
    场景三:
    location ^~ /aaa/ {
        proxy_pass http://192.168.171.129:8080/;
    }
    代理后实际访问地址:http://192.168.171.129:8080/bbb.jsp
    
    场景四:
    location ^~ /aaa {
        proxy_pass http://192.168.171.129:8080/;
    }
    代理后实际访问地址:http://192.168.171.129:8080//bbb.jsp
    
    

    proxy_pass配置中url末尾不带/时,
    如url中包含path,则将原uri去除location匹配表达式后的内容拼接在proxy_pass中的url之后
    如url中不包含path,则直接将原uri拼接在proxy_pass中url之后;

     测试地址:http://192.168.171.129/aaa/bbb.jsp
     场景一:
     location ^~ /aaa/{
        proxy_pass http://192.168.171.129:8080/server;
     }
     代理后实际访问地址:http://192.168.171.129:8080/serverbbb.jsp
    场景二:
    location ^~ /aaa {
        proxy_pass http://192.168.171.129:8080/server;
    }
    代理后实际访问地址:http://192.168.171.129:8080/server/bbb.jsp
    
    
    ----------------全转发-----------------------------------------------------------------------------
    场景三:
    location ^~ /aaa/ {
        proxy_pass http://192.168.171.129:8080;
    }
    代理后实际访问地址:http://192.168.171.129:8080/aaa/bbb.jsp
    
    场景四:
    location ^~ /aaa {
        proxy_pass http://192.168.171.129:8080;
    }
    代理后实际访问地址:http://192.168.171.129:8080/aaa/bbb.jsp
    

    相关文章

      网友评论

          本文标题:nginx配置proxy_pass时url末尾带“/”与不带“/

          本文链接:https://www.haomeiwen.com/subject/lddpprtx.html