zoukankan      html  css  js  c++  java
  • nginx location 以及 proxy_pass 的几种情况 以/结尾的问题

    工作中遇到nginx的location 和proxy_pass 有无/(根)结尾的区别

    在location中匹配的url最后有无/结尾,指的是模糊匹配与精确匹配的问题

    在proxy_pass中代理的url最后有无/结尾(不能作为判断依据),指的是在proxy_pass 指定的url后要不要替换掉location里面匹配到的字符串

    单纯从proxy_pass的问题上来说, 不能以有没有/结尾来判断, 而是以有没有uri来判断.

    只要在 域名:端口 后面加上了任何以/开头的字符串, 就被视为有uri, 规则就会发生改变. 有uri就会把请求的uri拼到proxy_pass的url后面, 然后整个替换掉location里面匹配的字符串.

    举例如下

    1)没有"/"结尾时,location /abc/def 可以匹配/abc/defghi的请求,也可以匹配/abc/def/ghi ......
    2)有"/"结尾时,location /abc/def/ 不能匹配/abc/defghi的请求,只能精确匹配 /abc/def/ghi这样的请求

    proxy_pass举例如下:

    #情况1
    location /proxy/ {
        proxy_pass http://myblog.com:8000/;
    }
    # proxy_pass的最终地址就是: http://myblog.com:8000/login.html  
    # 因为proxy_pass 在端口号后面有以/开头的uri,代表绝对路径,所以会忽略匹配到的/proxy/, 直接将/proxy/ 整个从url里面删除.
    
    #情况2
    location /proxy/ {
        proxy_pass http://myblog.com:8000;
    }
    #proxy_pass 代理到 http://myblog.com:8000/proxy/login.html
    
    #情况3
    location /proxy/ {
        proxy_pass http://myblog.com:8000/disquz/;
    }
    #proxy_pass 代理到http://myblog.com:8000/disquz/login.html
    
    #情况4
    location /proxy/ {
        proxy_pass http://myblog.com:8000/disquz;
    }
    # proxy_pass 代理到http://myblog.com:8000/disquzlogin.html  
    # 因为在端口号后面有/disquz 以/开头的uri, 所以会将/proxy/完全替换, 故/proxy/login.html 只剩下login.html 拼在url后面就会成为http://myblog.com:8000/disquzlogin.html
    
    #情况5
    location /proxy {
        proxy_pass http://myblog.com:8000/disquz/;
    }
    # proxy_pass 代理到http://myblog.com:8000/disquz//login.html  
    # 因为匹配到了这个规则 所以把uri里面的/proxy去掉 剩下/login.html, 拼在url后面就是http://myblog.com:8000/disquz//login.html
  • 相关阅读:
    ADB命令大全
    Backup your Android without root or custom recovery -- adb backup
    Content portal for Pocketables Tasker articles
    Is there a way to detect if call is in progress? Phone Event
    Tasker to proximity screen off
    Tasker to detect application running in background
    Tasker to create toggle widget for ES ftp service -- Send Intent
    Tasker to proximity screen on
    Tasker to answer incoming call by pressing power button
    Tasker to stop Poweramp control for the headset while there is an incoming SMS
  • 原文地址:https://www.cnblogs.com/btxlc/p/13426934.html
Copyright © 2011-2022 走看看