我设置了nginx位置重定向,以将/my_route
重定向到即将发布的页面,但允许/my_route?db=preview
传递到代理服务器。
location /my_route {
if ($arg_db != "preview") {
rewrite ^ /coming-soon/ last;
}
<other location config for when db == preview>
}
我想增加一层复杂性,以支持即将推出的页面的多种语言。
破坏nginx的配置,但给你一个主意:
location /my_route {
if ($arg_db != "preview") {
if ($arg_lang == "es") {
rewrite ^ /coming-soon/index_es.html last;
}
rewrite ^ /coming-soon/ last;
}
<other location config for when db == preview>
}
我知道if is evil,所以很高兴不再使用if
,如果需要的话,但是我不知道看哪个方向。我只知道nginx不支持&&
语句或嵌套的if
语句。
您可以使用map
消除内部的if
块。
例如:
map $arg_lang $mylang {
default /;
es /index_es.html;
}
server {
...
rewrite ^ /coming_soon$mylang last;
...
}
有关详细信息,请参见this document。