http 404 fallback multiple servers

raw

nginx.conf

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
location / {
    # Send 404s to B
    error_page 404 = @backendB;
    proxy_intercept_errors on;
    log_not_found  off;
 
    # Try the proxy like normal
    proxy_set_header X-Forwarded-For $remote_addr;
    proxy_set_header Host $host;
    proxy_set_header X-Real-IP  $remote_addr;
    proxy_pass http://A;
}
 
location @backendB {
    # If A didn't work, let's try B.
    proxy_set_header X-Forwarded-For $remote_addr;
    proxy_set_header Host $host;
    proxy_set_header X-Real-IP  $remote_addr;
    proxy_pass http://B;
 
    # Any 404s here are handled normally.
}
raw

nginx2.conf

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
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;
}
Christian Weiske Christian Weiske
owner

History