我可以在try_files nginx指令中使用两个命名位置吗?

Eug*_*kov 3 location nginx

我想使用类似的东西:

location @a1 {
    ...
}

location @a2 {
    ...
}

location /path {
    try_files @a1 $uri @a2
}
Run Code Online (Sandbox Code Playgroud)

是否有可能,我应该在@ a1位置继续尝试使用$ uri/@ a2?

如果是这样,nginx将如何处理?

Eug*_*kov 5

我找到了这个解决方案:

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;
}
Run Code Online (Sandbox Code Playgroud)

这个例子的作用如下:

try_files $uri @static_svr1 @static_svr2 @static_svr3
Run Code Online (Sandbox Code Playgroud)