Question about nested locations / PHP.

Cliff Wells cliff at develix.com
Sat Mar 10 00:47:56 UTC 2012


On Fri, 2012-03-09 at 22:12 +0000, Adrian Hayter wrote:
> Not sure if this is the right place to post this; apologies in advance if it is!
> 
> I'm having a bit of trouble with nested locations and PHP. I have a
> setup where I want all PHP files to go through fastcgi, and have an
> expiry of epoch. However, one particular PHP file is used to generate
> CSS stylesheets, and I want this file to have an expiry of 30 days. My
> current code looks like this:
> 
> location ~ \.php$
> {
> 	location ~ /css.php
> 	{
> 		expires 30d;
> 		add_header Pragma public;
> 		add_header Cache-Control "public";
> 	}
> 
> 	expires epoch
> 
> 	// Fastcgi stuff...
> }
> 


You don't need nested locations.  This should work:

location = /css.php {
    expires 30d;
    add_header Pragma public;
    add_header Cache-Control "public";
    include fastcgi_params;
    fastcgi_pass ...
}

location ~ \.php$ {
   expires epoch
   include fastcgi_params;
   fastcgi_pass ...
}

Information on the order of processing can be found here:

http://nginx.org/en/docs/http/request_processing.html#simple_php_site_configuration
http://wiki.nginx.org/HttpCoreModule#location



Regards,
Cliff



> Thanks in advance!
> 
> Adrian
> _______________________________________________
> nginx mailing list
> nginx at nginx.org
> http://mailman.nginx.org/mailman/listinfo/nginx




More information about the nginx mailing list