NGINX Failover Setup


From Docunext Technology Wiki

Jump to: navigation, search

NGINX can act as a failover in an interesting way: by setting the 404 path to be a location which proxies to another machine. I've only read about this and I want to set it up soon. I just got failover with Varnish working, so that is very good.

Index Issues

I've had some problems with directory indexes which I think I figured out, but can't remember the exact solution at the moment. I'll have to dig that up and put it here.

Try Files

For 0.7+, the try_files parameter may be what I'm looking for:

location / {
  try_files index.html @failover;
}
 
location @failover {
  root /var/www/error;
  index index.html;
}

I'll have to do some testing. Yes, I remember the problem. If a directory index is suggested in a request and is available as a file which is tried, its all good. But if there is no index file there and auto-indexing is disabled, a 403 forbidden response is generated. This works for me:

    location /s/ {
        index index.html;
        root /var/www/public/;
        try_files $uri @failover;
        error_page 403 @failover;
    }

    location @failover {
        proxy_set_header Host www.docunext.com;
        proxy_pass http://192.168.8.101:80;
    }

Nevertheless, a 403 error is generated.

403 errors aside, this is working well for me with regards to missing files.

See Also

Personal tools