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

2016-12-12 15:22:12 +08:00
 ghostcir

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
3161 次点击
所在节点    NGINX
12 条回复
sola97
2016-12-12 20:11:31 +08:00
加个[]试试
sola97
2016-12-12 20:13:04 +08:00
我看错了,无视吧
majinjing3
2016-12-12 20:16:50 +08:00
/test/(.*)$
lhbc
2016-12-12 20:17:20 +08:00
因为 URI 不允许有两个?
majinjing3
2016-12-12 20:26:27 +08:00
@lhbc 你是对的,无视我吧,
ghostcir
2016-12-12 20:41:11 +08:00
@lhbc 并不是这个原因,带?号只是我为了调试方便,另外还有#也会产生同样的结果
hanyouchun66
2016-12-12 21:55:24 +08:00
$query_string
lhbc
2016-12-12 21:57:34 +08:00
@ghostcir 所有 http server 都会忽略#和后面的字符串
bikong0411
2016-12-12 22:45:35 +08:00
location 不匹配 querystring
hanyouchun66
2016-12-13 09:53:39 +08:00
@bikong0411
location ^~ /test {
proxy_pass https://xxx/test.php?$query_string;
}
不是在 location 里用
zhangsen1992
2016-12-13 14:13:08 +08:00
是没有转义的原因么?
bikong0411
2016-12-14 23:27:20 +08:00
@hanyouchun66 这样可以

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/327068

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX