[英]find a cleaner nginx location using regexp
I would like to create a location that matches all but 我想创建一个匹配所有位置的位置
http://uri/proxy-wmts
For example: 例如:
http://uri/proxy/toto
http://uri/proxy?param=value
I came out with that: 我出来的是:
location ~ ([^/]*)/proxy(\-[^w][^m][^t][^s])*
But I think it's kind of ugly, I am looking for a cleaner solution. 但我认为这很丑陋,我正在寻找更清洁的解决方案。
As I already stated in my comment, using proper location
order would be much easier and more performant (matching a constant string is faster than a regular expression). 正如我在评论中已经指出的那样,使用正确的
location
顺序会容易得多,并且性能更高(匹配常量字符串比使用正则表达式更快)。
location = /proxy-wmts {} # matches *exactly* /proxy-wmts
location /proxy {}
or 要么
location /proxy-wmts {} # also matches /proxy-wmts....
location /proxy {}
would pretty much do what you want. 几乎可以做你想要的。
(?!...)
:
(?!...)
:
location ~ ([^/]*)/proxy(?!-wmts)
Which will match for 哪个适合
/uri/proxy
/uri/proxy-abc
/uri/proxy/abc
...
but not for 但不是
/uri/proxy-wmts
/uri/proxy-wmts-abc
/uri/proxy-wmts/abc
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.