Strange try_files behaviour

Maxim Dounin mdounin at mdounin.ru
Sun Jul 13 21:13:50 UTC 2014


Hello!

On Sat, Jul 12, 2014 at 06:23:41AM -0400, itpp2012 wrote:

> Hmm, more debugging, this config returns a 404 from the backend (which it
> shouldn't):
> 
> try_files $uri $uri/ =404;
> set $maintmode S; 
> if ($remote_addr ~ "^(192.168.*.*)$") { set $maintmode L; }
> if (-f $document_root/maintenance_mode.html) { set $maintmode
> "${maintmode}M"; }
> if ($maintmode = SM) { return 503; }
> 
> This config returns a 404 from nginx, like it should:
> 
> try_files $uri $uri/ =404;
> set $maintmode S; 
> # if ($remote_addr ~ "^(192.168.*.*)$") { set $maintmode L; }
> if (-f $document_root/maintenance_mode.html) { set $maintmode
> "${maintmode}M"; }
> if ($maintmode = SM) { return 503; }
> 
> 
> So yes it is an IF issue but to my opinion this should not happen.

Please re-read the link provided by Valentin:

http://wiki.nginx.org/IfIsEvil

One of the examples there is exactly your case - if any of the if's 
(without "return" inside it) in your configuration is matched, the 
"try_files" won't work.

-- 
Maxim Dounin
http://nginx.org/



More information about the nginx mailing list