Nginx:proxy_pass 不能在 "if" 语句内的位置包含 URI 部分
Nginx: proxy_pass cannot have URI part in location inside "if" statement
假设有一个nginx配置:
server {
...
location /nakayoshi {
if ($georedirect) {
proxy_pass http://foo.bar/fa/fb/fc;
}
proxy_pass http://foo.bar/fa/fb/fd;
}
}
当我sudo nginx -t
时,它打印出:
nginx: [emerg] "proxy_pass" cannot have URI part in location given by regular express, or inside named location, or inside "if" statement, or inside "limit_except" block in /etc/nginx/conf.d/nakayoshi.conf
我还发现 rewrite
在这里帮助我,但是重定向的 uri 将更改为类似“http://foo.bar/fa/fb/fc”的 url。
我可以使用 proxy_pass
保持重定向的 uris 不变吗?
尝试这样的事情
http {
...
map $georedirect $proxyuri {
"" fa/fb/fd;
default fa/fb/fc;
}
server {
...
location /nakayoshi {
proxy_pass http://foo.bar/$proxyuri;
}
}
}
假设有一个nginx配置:
server {
...
location /nakayoshi {
if ($georedirect) {
proxy_pass http://foo.bar/fa/fb/fc;
}
proxy_pass http://foo.bar/fa/fb/fd;
}
}
当我sudo nginx -t
时,它打印出:
nginx: [emerg] "proxy_pass" cannot have URI part in location given by regular express, or inside named location, or inside "if" statement, or inside "limit_except" block in /etc/nginx/conf.d/nakayoshi.conf
我还发现 rewrite
在这里帮助我,但是重定向的 uri 将更改为类似“http://foo.bar/fa/fb/fc”的 url。
我可以使用 proxy_pass
保持重定向的 uris 不变吗?
尝试这样的事情
http {
...
map $georedirect $proxyuri {
"" fa/fb/fd;
default fa/fb/fc;
}
server {
...
location /nakayoshi {
proxy_pass http://foo.bar/$proxyuri;
}
}
}