Can try_files be allowed outside of location {} ?

Igor Sysoev is at rambler-co.ru
Fri Mar 20 09:01:48 MSK 2009


On Thu, Mar 19, 2009 at 10:43:43PM -0700, mike wrote:

> 2009/3/19 Igor Sysoev <is at rambler-co.ru>:
> > On Thu, Mar 19, 2009 at 10:17:45PM -0700, mike wrote:
> >
> >> I get a warning when placing it outside of a location block. I don't
> >> think it -needs- to be inside of one. Would be nice to team up with
> >> the patch you made for the next release... :)
> >
> > I'm not sure that it should be done.
> > Could you show use case ?
> 
> for a site basically dedicated to a single app... no need for location / {}
> 
> server {
>         listen 80;
>         server_name michaelshadle.com;
>         index index.php index.html;
>         root /home/mike/web/michaelshadle.com;
>         include /etc/nginx/defaults.conf;
>         include /etc/nginx/expires.conf;
>         try_files $uri $uri/ /wordpress/index.php?q=$uri;
>         location ~ \.php$ {
>                 fastcgi_pass 127.0.0.1:11000;
>         }
> }
> 
> my current workaround:
> 
> server {
>         listen 80;
>         server_name michaelshadle.com;
>         index index.php index.html;
>         root /home/mike/web/michaelshadle.com;
>         include /etc/nginx/defaults.conf;
>         include /etc/nginx/expires.conf;
> 
>         location / {
>                 try_files $uri $uri/ /wordpress/index.php?q=$uri;
> 
>         location ~ \.php$ {
>                 fastcgi_pass 127.0.0.1:11000;
>         }
>         }
> }
> 
> A nit bit-picky but I don't see the need for the restriction, unless
> the code is very difficult for it.

Actually, I have decided from the very start that each server {} should
have "location / {}" and it was surprise for me when people started to
use configurations as in the 1st example. There are even some bugfixes
related to this since I did not expect such usage.

I will think if try_files in server{} is possible. You may try the attached
patch, it just enable try_files in server context (warning, I did not test it).


-- 
Igor Sysoev
http://sysoev.ru/en/
-------------- next part --------------
Index: src/http/ngx_http_core_module.c
===================================================================
--- src/http/ngx_http_core_module.c	(revision 1903)
+++ src/http/ngx_http_core_module.c	(working copy)
@@ -542,7 +542,7 @@
       NULL },
 
     { ngx_string("try_files"),
-      NGX_HTTP_LOC_CONF|NGX_CONF_2MORE,
+      NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_2MORE,
       ngx_http_core_try_files,
       NGX_HTTP_LOC_CONF_OFFSET,
       0,


More information about the nginx mailing list