How to serve PHP files outside the public folder?

For serving the PHP scripts, I use this location

location ~ .php$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include /etc/nginx/fastcgi_params;
}

now I want to keep a folder outside the public folder to be served as a

location /private/ {
/* serving static files from /private/$server_name/ /
location ~ .php$ {
/
serving PHP scripts from /private/$server_name/ */
}
}

How should set this location to serve the files from outside the public
folder?

Posted at Nginx Forum:

Hi,

Maybe you can try something like this;

location /private/ {
try_files @private
}

location @private {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include /etc/nginx/fastcgi_params;
}

Regards,
Ron

On Sun, Aug 25, 2013 at 03:14:55AM -0400, etrader wrote:

folder?
http://nginx.org/r/location

Probably one of “location ^~ /private/”; or else “location ~
/private/*.\php$” before your “location ~ .php$”, should work.

f

Francis D. [email protected]

On Mon, Aug 26, 2013 at 11:12:15PM +0100, Francis D. wrote:

Probably one of “location ^~ /private/”; or else “location ~
/private/*.\php$” before your “location ~ .php$”, should work.

That’s “^/private/*.php$”, of course. Fat fingers…

f

Francis D. [email protected]