zoukankan      html  css  js  c++  java
  • 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

  • 相关阅读:
    免费linux远程主机nitrousIO
    利用PyWapFetion发免费天气短信
    接口中的 sort排序 + md5加密
    即点即改心得
    js判断客户端访问是安卓还是ios
    php将时间戳转换成几小时前的格式封装
    前端请求接口出现的跨域问题
    使用redis技术实现注册登录列表以及关注功能
    windows下的redis安装以及扩展安装
    Yii2 学习心得
  • 原文地址:https://www.cnblogs.com/dwj192/p/13967376.html
Copyright © 2011-2022 走看看