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