【发布时间】:2016-10-24 02:05:08
【问题描述】:
我想使用类似的东西:
location @a1 {
...
}
location @a2 {
...
}
location /path {
try_files @a1 $uri @a2
}
我应该在@a1 位置继续尝试 $uri / @a2 吗?
如果是这样,nginx 将如何处理?
【问题讨论】:
我想使用类似的东西:
location @a1 {
...
}
location @a2 {
...
}
location /path {
try_files @a1 $uri @a2
}
我应该在@a1 位置继续尝试 $uri / @a2 吗?
如果是这样,nginx 将如何处理?
【问题讨论】:
我找到了this solution:
location /static/ {
try_files $uri @static_svr1;
}
location @static_svr1{
proxy_pass http://192.168.1.11$uri;
proxy_intercept_errors on;
recursive_error_pages on;
error_page 404 = @static_svr2;
}
location @static_svr2{
proxy_pass http://192.168.1.12$uri;
proxy_intercept_errors on;
recursive_error_pages on;
error_page 404 = @static_svr3;
}
location @static_svr3{
proxy_pass http://192.168.1.13$uri;
}
这个例子的工作原理是:
try_files $uri @static_svr1 @static_svr2 @static_svr3
【讨论】:
您不能,因为 try_files 只会将其 last 参数视为命名位置 - 在您的示例中,nginx 将查找名为 @a1 的文件并忽略 location @a1 块。
try_files docs 对此并不十分明确,只是提到“最后一个参数也可以指向一个命名位置”。
This answer 显示了一个使用error_page 的解决方法,这可能对您有用(取决于您想通过进入@a1 执行什么操作)。
【讨论】: