V2EX = way to explore
V2EX 是一个关于分享和探索的地方
Sign Up Now
For Existing Member  Sign In
NGINX
NGINX Trac
3rd Party Modules
Security Advisories
CHANGES
OpenResty
ngx_lua
Tengine
在线学习资源
NGINX 开发从入门到精通
NGINX Modules
ngx_echo
ghostcir
V2EX  ›  NGINX

求教下 nginx 正则不匹配"?"号是什么原因

  •  
  •   ghostcir · Dec 12, 2016 · 4114 views
    This topic created in 3432 days ago, the information mentioned may be changed or developed.

    nginx 规则

        location ~ /test/(.*) {
            proxy_pass               https://xxx/test.php?$1;
        }
    

    php代码

    <?php
    echo $_SERVER['REQUEST_URI'];
    echo "\r\n";
    

    结果

    #curl http://xxx/test/123456
    /test.php?123456
    #curl http://xxx/test/12?132
    /test.php?12
    
    12 replies    2016-12-14 23:27:20 +08:00
    sola97
        1
    sola97  
       Dec 12, 2016
    加个[]试试
    sola97
        2
    sola97  
       Dec 12, 2016
    我看错了,无视吧
    majinjing3
        3
    majinjing3  
       Dec 12, 2016 via Android
    /test/(.*)$
    lhbc
        4
    lhbc  
       Dec 12, 2016 via iPhone
    因为 URI 不允许有两个?
    majinjing3
        5
    majinjing3  
       Dec 12, 2016 via Android
    @lhbc 你是对的,无视我吧,
    ghostcir
        6
    ghostcir  
    OP
       Dec 12, 2016
    @lhbc 并不是这个原因,带?号只是我为了调试方便,另外还有#也会产生同样的结果
    hanyouchun66
        7
    hanyouchun66  
       Dec 12, 2016   ❤️ 1
    $query_string
    lhbc
        8
    lhbc  
       Dec 12, 2016 via iPhone
    @ghostcir 所有 http server 都会忽略#和后面的字符串
    bikong0411
        9
    bikong0411  
       Dec 12, 2016 via Android
    location 不匹配 querystring
    hanyouchun66
        10
    hanyouchun66  
       Dec 13, 2016
    @bikong0411
    location ^~ /test {
    proxy_pass https://xxx/test.php?$query_string;
    }
    不是在 location 里用
    zhangsen1992
        11
    zhangsen1992  
       Dec 13, 2016
    是没有转义的原因么?
    bikong0411
        12
    bikong0411  
       Dec 14, 2016 via Android
    @hanyouchun66 这样可以
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   3273 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 43ms · UTC 12:26 · PVG 20:26 · LAX 05:26 · JFK 08:26
    ♥ Do have faith in what you're doing.