Strange rewrite behaviour

Francis Daly francis at
Mon Mar 14 19:49:11 MSK 2011

On Mon, Mar 14, 2011 at 05:37:28PM +0200, Alexander Economou wrote:

Hi there,

a few suggestions first, which are *not* related to the reported problem:

> ------------------------------------------------------------------------
> server {
>      listen 80;
>      server_name;
>      access_log 
> /var/www/cluster-domains/2_socialwhale_com/logs/2.socialwhale.log main;
>      error_log 
> /var/www/cluster-domains/2_socialwhale_com/logs/2.socialwhale.err;
>      index index.html index.htm index.php;
>      root  /var/www/cluster-domains/2_socialwhale_com/htdocs/website;

Setting "root" there is good. If you don't set it inside a particular
location{} block, that value will be inherited (and available as

> location ~ \.php$ {
>             root 
> /var/www/cluster-domains/2_socialwhale_com/htdocs/website; you could safely omit that line...

>             fastcgi_pass;
>             fastcgi_index  index.php;
>             fastcgi_param  SCRIPT_FILENAME 
> /var/www/cluster-domains/2_socialwhale_com/htdocs/website/$fastcgi_script_name;

...and shorten that line. And then, in future, if you switch directory,
you'll have fewer places to update in the config file.

>             include        fastcgi_params;

Or, instead, you could "include fastcgi.conf" and omit the SCRIPT_FILENAME
line altogether.

>         }
>         error_page  404              /404.html;
>        	location = /404.html {
>             root   /usr/share/nginx/html;
>         }
> location  /var/www/cluster-domains/2_socialwhale_com/htdocs/website {
>     auth_basic            "Restricted";
>     auth_basic_user_file 
> /var/www/cluster-domains/2_socialwhale_com/htpasswd;
>     }

That block probably does not do what you want it to. "location" acts on
urls, not file paths. But it's also unrelated to the reported problem.

> Now if i add the following just after the error_page definition
> location / {
>    try_files $uri $uri/ index.php?$uri&$args;
> 	}
> Nginx says the configuration is ok but php-cgi crashes....

I'd probably use "/index.php" instead of "index.php" up there. Depending
on what you mean by "php-cgi crashes", maybe that will help?

If not, then details of what you see vs what you expect to see will
probably help find the problem.

Good luck with it,

Francis Daly        francis at

More information about the nginx mailing list