美文网首页Nginx专题
Nginx proxy_pass 后面的url 加/与不加/的区

Nginx proxy_pass 后面的url 加/与不加/的区

作者: Lisong | 来源:发表于2019-05-13 17:44 被阅读0次

    在nginx中配置proxy_pass时,当在后面的url加上了/,相当于是绝对根路径,则nginx不会把location中匹配的路径部分代理走;如果没有/,则会把匹配的路径部分也给代理走。


    下面四种情况分别用 http://192.168.1.4/proxy/test.html 进行访问。


    第一种
    location  /proxy/ {
        proxy_pass http://127.0.0.1:81/;
    }
    

    会被代理到 http://127.0.0.1:81/test.html 这个url


    第二咱(相对于第一种,最后少一个 / ) (proxy_pass 参数中如果不包含url的路径,则会将location的pattern识别的路径作为绝对路径。)
    location  /proxy/ {
        proxy_pass http://127.0.0.1:81;
    }
    

    会被代理到 http://127.0.0.1:81/proxy/test.html 这个url


    第三种:
    location  /proxy/ {
        proxy_pass http://127.0.0.1:81/ftlynx/;
    }
    

    会被代理到 http://127.0.0.1:81/ftlynx/test.html 这个url。


    第四种情况(相对于第三种,最后少一个 / ):
    location  /proxy/ {
        proxy_pass http://127.0.0.1:81/ftlynx;
    }
    

    会被代理到 http://127.0.0.1:81/ftlynxtest.html 这个url

    相关文章

      网友评论

        本文标题:Nginx proxy_pass 后面的url 加/与不加/的区

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