drupal+nginx: this works => using try_files

mike mike503 at gmail.com
Tue Mar 17 20:15:45 MSK 2009

2009/3/17 Mark Alan <varia at e-healthexpert.org>:
> The following has been tested in Nginx  0.7.42 + Drupal 6.10 + Ubuntu 8.10.
> M.

Seems to me that

a) drupal should not include scripts/etc. that should not be ran via
the web -in- the webroot, or
b) they should be localized to only one directory

>        # hide drupal system files
>        location ~*
> ((cron\.php|settings\.php)|\.(htaccess|engine|inc|info|install|module|profile|pl|po|sh|.*sql|theme|tpl(\.php)?|xtmpl)$|^(Entries.*|Repository|Root|Tag|Template))$
> {
>                deny all;
>        }

That is ugly as sin to me, and could change at any given time. Is
there a true need to protect all of these? Is it only a specific
folder?You could always use location /folder { internal; } then too.

you can add these to fastcgi_params, no need for repetition:
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_index index.php;

I'm just trying to approach this from a purely KISS perspective. I
hate seeing denormalized/excessive configs. Especially since I host a
drupal instance I want the cleanest possible ;)

and actually, since drupal has nothing really specific besides a
single line, you could get away with:

try_files $uri $uri/ /index.php?q=$request_uri;            ($uri might
work too - might warrant testing the two, I'm trying to find the
difference between the two on the wiki)

I also have an open question to the list about using try_files with
multiple prefixes... i.e.:

location /drupal {
 try_files $uri $uri/ /drupal/index.php?q=$request_uri

# wordpress, for example
location /blog {
 try_files $uri $uri/ /blog/index.php?q=$request_uri

I don't really like the current wiki examples either. It's got a mix
of parsing php and try_files and other wacky stuff that will just lead
to confusion.

More information about the nginx mailing list