我在 nginx 中有一个位置,其中 GET 和 POST 请求应该发送到不同的命名位置。但这段代码不起作用:
if ( $request_method = GET ) {
try_files /NON-EXISTENT @named_location_get
}
if ( $request_method = POST ) {
try_files /NON-EXISTENT @named_location_post
}
Run Code Online (Sandbox Code Playgroud)
因为try_files
不准进去if
。
还有其他方法可以将请求重定向到指定位置吗if
?
我不知道在哪里记录了这一点,但我看到了在符号后面使用变量的配置@
,以使命名条件成为location
条件。
将其与map
块一起使用,您可以消除if
块。
我已经测试过这个例子:
map $request_method $name {
GET named_location_get;
POST named_location_post;
default named_location_other;
}
server {
...
location ... {
try_files nonexistent @$name;
}
location @named_location_get {
...
}
...
}
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
918 次 |
最近记录: |