rewrite except one directory

Jim Ohlstein jim at ohlste.in
Sun Feb 16 20:38:07 UTC 2014


Hello,

On 2/16/14, 2:57 PM, Philipp Kraus wrote:
> Hi
>
> thanks for your answer, seems to be working
>
>> ==
>> location ^~ /scripts/ {
>> # do your /scripts/ stuff
>> }
>> location / {
>> # do everything else
>> }
>> ==
>
>
> I have defined my script location with:
>
>      location ~ \.php$ {
>          fastcgi_pass   127.0.0.1:9000;
>          include /etc/nginx/fastcgi_params;
>      }
>
>      location ^~/scripts
>      {
>          alias /home/www/content/scripts;
>      }
>
> but in my alias path there are stored PHP scripts and at the moment
> I get a download of the script but the script is not pushed to the fast-cgi
> process. How can I enabled in the script location the PHP CGI for *.php
> files?
>

With a nested location, or, if all the contents of 
/home/www/content/scripts are PHP scripts, use a fastcgi_pass.

Remember, all requests are handed by one location, and one location 
only. Writing instructions for how to handle PHP scripts in one location 
does not tell nginx how to handle them in other locations.

So:

	location ^~/scripts {
         	alias /home/www/content/scripts;
		fastcigi_pass 127.0.0.1;
		include /etc/nginx/fastcgi_params;
	}


Or, if you have content there other than PHP scripts in the alias location:

	location ^~/scripts {
         	alias /home/www/content/scripts;
		location ~\.php$ {
			fastcigi_pass 127.0.0.1;
			include /etc/nginx/fastcgi_params;
		}
	}

-- 
Jim Ohlstein


"Never argue with a fool, onlookers may not be able to tell the 
difference." - Mark Twain



More information about the nginx mailing list