Nginx:proxy_pass不能在位置内有URI部分"如果"声明

时间:2015-02-02 10:47:02

标签: nginx

假设有一个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”这样的网址。

我可以使用proxy_pass保持重定向的uris不变吗?

1 个答案:

答案 0 :(得分:0)

尝试这样的事情

http {
    ...
    map $georedirect $proxyuri {
        "" fa/fb/fd;
        default fa/fb/fc;
    }
    server {
        ...
        location /nakayoshi {
            proxy_pass http://foo.bar/$proxyuri;
        }
    }
}