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

  • 相关阅读:
    C#使用Json.Net遍历Json
    晓晨高效IP提取工具 附源码
    JavaScript原生秒表、计时器
    网盘直链工具 winform版 V1.0
    【架构】RPC 使用 Haproxy、keepalive作为负载均衡
    【架构】Google的大规模集群管理工具Borg
    【Networking】gRPC golang 相关资料
    【Linux】find grep 联合使用 过滤所有子目录、文件
    【Storage】Ubuntu LVM 安装配置
    【Ansible】SSH Error: ssh_exchange_identification: Connection closed by remote host
  • 原文地址:https://www.cnblogs.com/dwj192/p/13967376.html
Copyright © 2011-2022 走看看