why "if" can not be used within "if"?

merlin corey merlincorey at dc949.org
Sat Jul 25 15:50:43 MSD 2009

2009/7/24 Igor Sysoev <is at rambler-co.ru>:
> Currently "if" is ugly hack.

To very slightly expand upon what Igor said, here is my understanding.
 If is an ugly hack that essentially (within a location, anyway) is
actually another psuedo-location (I think you'll see this too if you
look into code more).  On the flip side, this means many ifs can (and
should) be replaced by use of location directives in combination with
try_files directives.  Finally, and a little more philosophically, in
general the nginx configuration is a nice declarative statement about
your sites' layouts; on the other hand, "if" is an imperative
statement that breaks from this flow and is somewhat out of place.

Unfortunately, currently, there are some things you can only do with
an if.  For those cases, I ask you, do you really want a much more
complicated configuration?  Seems to me simplest is best, especially
when you have to use if!  Debugging issues with ifs I remember being
not a lot of fun in 0.6.x - try_files made it so I don't have to do
that anymore in 0.7.x and above and I am happier for it!  Good luck,

-- Merlin

More information about the nginx mailing list