似乎Nginx无法支持当proxy_pass设置为变量时的重定向。有没有什么方法可以实现这个功能,比如通过链式服务器或其他解决方法?为什么不支持这个功能呢?
.conf文件如下:
proxy_pass $var;
proxy_redirect default;
我收到的错误信息是:
nginx:[emerg]“proxy_redirect default”不能与带有变量的“proxy_pass”指令一起使用。
似乎Nginx无法支持当proxy_pass设置为变量时的重定向。有没有什么方法可以实现这个功能,比如通过链式服务器或其他解决方法?为什么不支持这个功能呢?
.conf文件如下:
proxy_pass $var;
proxy_redirect default;
您可以通过指定完整的重定向语句来解决这个问题,而不是使用“默认”选项。
根据nginx文档:
The default replacement specified by the default parameter uses the parameters of the location and proxy_pass directives. Hence, the two configurations below are equivalent:
location /one/ { proxy_pass http://upstream:port/two/; proxy_redirect default; location /one/ { proxy_pass http://upstream:port/two/; proxy_redirect http://upstream:port/two/ /one/;
因此,要替换“默认”指令,您需要将“proxy_pass”的值用作“proxy_redirect”的第一个参数,并将“location”的值用作第二个参数。
我曾经遇到过同样的问题,而拯救我的是Nginx的解析器模块。
尝试添加以下内容:
resolver 8.8.8.8;