How nginx's "location if" works (Was Re: Setting cache parameters via if directives)

Ryan Malayter malayter at
Tue Feb 15 22:00:22 MSK 2011

On Sun, Feb 13, 2011 at 11:27 PM, agentzh <agentzh at> wrote:
> You see, how tricky it is behind the scene! No wonder people keep
> saying "nginx's if is evil".

I very much see why "if is evil", but unfortunately there seems to be
almost no alternative if you want to take some action based on things
in headers or other variables.

So what is a generally safe way to handle control flow where the
conditions are based on something that is not in the URI (making
rewrite useless)?

Note that changing the back-end application to handle things is often
not possible when using commercial web applications behind nginx.

I guess this sort of thing could always be a job for a general-purpose
web server like Apache. Nginx is meant to be simple and lightweight;
perhaps the general design is at odds with complex flow control.


More information about the nginx mailing list