• Nginx配置转发


    nginx location proxy_pass 后面的url 加与不加/的区别

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

     首先是location进行的是模糊匹配
    
    1)没有“/”时,location /abc/def可以匹配/abc/defghi请求,也可以匹配/abc/def/ghi等
    2)而有“/”时,location /abc/def/不能匹配/abc/defghi请求,只能匹配/abc/def/anything这样的请求

    下面四种情况分别用http://luxingda.top/py/test 进行访问。

    第一种:

    location  /py/ {
    
    proxy_pass http://127.0.0.1:5000/;
    
    }

    结论:会被代理到http://127.0.0.1:5000/test  这个url

    第二种(相对于第一种,最后少一个 /)

    location  /py/ {
    
    proxy_pass http://127.0.0.1:5000
    ; }

    结论:会被代理到http://127.0.0.1:5000/py/test这个url

    第三种:

    location  /py/ {
    
    proxy_pass http://127.0.0.1:5000/py/;
    
    }

    结论:会被代理到http://127.0.0.1:5000/py/test这个url。

    第四种(相对于第三种,最后少一个 / ):

    location  /py/ {
    
    proxy_pass http://127.0.0.1:5000/py;
    
    }

    结论:会被代理到http://127.0.0.1:5000/pytest这个url

  • 相关阅读:
    joomla
    笨兔兔的故事(下)
    wine乱码
    笨兔兔的故事(中)
    gedit中文乱码
    php不常用函数
    android配置开发环境ubuntu
    笨兔兔的故事(上)
    关于linux编码
    linux常用命令小记
  • 原文地址:https://www.cnblogs.com/luxd/p/12097097.html
Copyright © 2020-2023  润新知