Upstream fail over?

Maxim Dounin mdounin at mdounin.ru
Mon Jul 27 00:56:00 MSD 2009


Hello!

On Sun, Jul 26, 2009 at 04:42:55PM +0200, Mitchua Mitchua wrote:

> merlin corey wrote:
> > Hello,
> > 
> > Yes, very easily with 0.7.x and above.  It would be something like
> > below ( check http://wiki.nginx.org/NginxHttpCoreModule#try_files )
> > 
> > location / {
> >   try_files @varnish @application;
> > }
> > 
> > location @varnish {
> >   // proxy to varnish
> > }
> > 
> > location @application {
> >   // proxy to application
> > }
> > 
> > -- Merlin
> 
> I tried a config like this on 0.8.6 and I found that all requests ended 
> up going to the @application proxy, skipping the @varnish proxy 
> entirely. Am I doing something wrong?

No, merlin's suggestion was misleading, try_files doesn't work 
this way - it checks static files existance and fallbacks last uri
if no one was found, e.g.

    location / {
        try_files /file1.html /file1.en.html @fallback;
    }

    location @fallback {
        proxy_pass ...
    }

For your task you should use error_page based fallback, e.g. to 
catch 404 errors from varnish and pass them to application use 
something like this:

    location / {
        error_page  404  = @fallback;
        proxy_intercept_errors on;

        # proxy to varnish
        proxy_pass ...;
    }

    location @fallback {
        # proxy to application
        proxy_pass ...;
    }

Maxim Dounin





More information about the nginx mailing list