需要匹配以commerce/authenticate结尾的所有URL,并且无法获得足够通用的规则。
下面是我需要匹配的URL:
我的尝试:
#
location ~ .*api/commerce/authenticate {
limit_except POST {
deny all;
}
}
# This also exists
location ^~ /madrid {
try_files $uri $uri/ /madrid/index.php?$query_string;
location ~ '\.php$|^/update.php' {
fastcgi_split_path_info ^(.+?\.php)(|/.*)$;
...
}
}上面的代码不起作用(匹配所有给定的URL),但是,如果我在中移动,它可以工作:
但正如我前面所解释的,我需要一个适用于根案例的一般规则。
发布于 2020-06-08 19:43:40
^字符在location ^~ /madrid中阻止nginx在检查这个位置之后检查正则表达式。
尝试以下配置:
location ~ api/commerce/authenticate$ {
limit_except POST {
deny all;
}
}
location /madrid {
try_files $uri $uri/ /madrid/index.php?$query_string;
location ~ '\.php$|^/update.php' {
fastcgi_split_path_info ^(.+?\.php)(|/.*)$;
...
}
}由于这个配置和请求是/madrid/api/commerce/authenticate,nginx首先看到前缀与/madrid匹配。它会记住匹配,然后继续检查正则表达式块。然后正则表达式块匹配,nginx将使用它。
如果正则表达式块不匹配,nginx将使用/madrid位置。
关于nginx位置处理规则的更多详细信息记录在http://nginx.org/en/docs/http/ngx_http_核心_module.html#location中。
https://serverfault.com/questions/1020572
复制相似问题