• nginx配置之proxy_pass路径加斜杠/以及包含路径的区别


    nginx配置看似简单,但一些细节配置经常被大家忽略。

    在proxy_pass中

    1.proxy_pass包含路径如 http://127.0.0.1:8080/abc 和http://127.0.0.1:8080规则都有区别。

    2.proxy_pass结尾加斜杠/和不加斜杠的有区别

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

    第一种(末尾加斜杠,proxy_pass中不包含路径):

    location  /proxy/ {

    proxy_pass http://127.0.0.1:81/;

    }

    结论:会被代理到http://127.0.0.1:81/test.html  (proxy_pass+请求url匹配的location路径后的内容)

    第二种(末尾不加斜杠,proxy_pass不包含路径)

    location  /proxy/ {

    proxy_pass http://127.0.0.1:81;

    }

    结论:会被代理到http://127.0.0.1:81/proxy/test.html (proxy_pass替换请求url的ip和端口)

    第三种(末尾加斜杠,proxy_pass包含路径):

    location  /proxy/ {

    proxy_pass http://127.0.0.1:81/abc/;

    }

    结论:会被代理到http://127.0.0.1:81/abc/test.html (proxy_pass+请求url匹配的location路径后的内容)

    第四种(末尾不加斜杠,url包含路径):

    location  /proxy/ {

    proxy_pass http://127.0.0.1:81/abc;

    }

    结论:会被代理到http://127.0.0.1:81/abctest.html (proxy_pass+请求url匹配的location路径后的内容)

    总结:

        1.如果proxy_pass后面有斜杠。转发url为proxy_pass+原url匹配的location路径之后的内容。

             例:原请求http://192.168.10.1/proxy/test.html,  location 为/proxy/

              proxy_pass为 http://127.0.0.1:81/abc/

             转发路径:(proxy_pass)http://127.0.0.1:81/abc/加上原请求部分路径test.html,最终路径http://127.0.0.1:81/abc/test.html

      2.proxy_pass后面没有斜杠,

          a.只有当proxy_pass只有IP加端口,无路径时。匹配规则为proxy_pass替换原请求url的ip和端口,

           同时保留了location路径。例子为上述的第二种情况。

           b.当proxy_pass端口后包含路径时,匹配规则同1.

     3.推荐:一般建议proxy_pass后面不包含路径

    转自:https://blog.csdn.net/u010786902/article/details/91414747

  • 相关阅读:
    PHP学习(二)
    PHP学习(一)
    JQuery学习小结
    Java学习(七)标准标签库JSTL
    Java学习(六)servlet 的引入
    Java学习(五)例题
    java学习(四)代码的设计
    Java学习(三)JSP学习1
    采用prometheus 监控mysql
    commonjs, nodejs, npm, browserify, watchify
  • 原文地址:https://www.cnblogs.com/dwj192/p/13967376.html
Copyright © 2020-2023  润新知