Nginx正则表达式没有设置变量

时间:2017-03-28 15:50:14

标签: curl nginx

我安装了Nginx 1.11.0,并且我正在尝试根据此正则表达式设置变量:

map $args $foo {
    "~(^|(?<pre>.*?)&)(cb\=[^&]+)(?<post>.*)"        "$pre$post";
    default                                            "cat";
}

此外,我有

    proxy_cache_key  "$scheme$host$uri$foo";
    add_header Cache-Buster "$foo";

当我启动Nginx并运行curl命令时:

curl -I localhost:80/?foo=test&cb=112&bar=test

我总是把猫作为回应。知道为什么吗?我通过在线正则表达式测试程序运行它,它似乎在线工作。

1 个答案:

答案 0 :(得分:0)

我很亲密。这就是我要找的东西:

"~(^|(?<pre>.*?)\&)((cb\=[^&]+)\&)(?<post>.*)"

在URL周围运行带有单引号的curl命令也有助于逃避&符号:

curl -I 'localhost/?foo=5&cb=234432&bar=test'