繁体   English   中英

如何在nginx.conf位置匹配问号“?”作为regexp

[英]How to match question mark “?” as regexp on nginx.conf location

我想匹配问号“?” 作为nginx.conf位置的正则表达式。

例如,我想匹配的URL模式是/某些?foo = 5或/ something?bar = 8(参数只能更改)。

因为nginx采用RCPE ,我可以在nginx.conf上写如下位置:

location ~ ^/something\?.* {
}

以上与URL模式不匹配。 我怎样才能做到这一点?

此外,以下不是我的期望。

location ~ ^/something?.* {
}

它会匹配/ something_foo_bar_buzz我不指望。

nginx位置块根本不匹配查询字符串。 所以这是不可能的。

地点

该指令允许根据URI进行不同的配置。

在nginx中,有一个内置变量$ uri,匹配位置块。 例如,提出请求

http://www.example.com/app/login.php?username=xyz&password=secret

$ uri值是这个字符串:

 /app/login.php

query_string存储在nginx变量$ args中:

username=xyz&password=secret

做某事。 查询字符串,你可以做类似的事情

if ($args ~ username=xyz) {
   # do something for requests with this query string
}

但要小心, IF是邪恶的

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM