Disable PHP in specific directories

Boris Dolgov boris at dolgov.name
Thu Jun 10 20:25:57 MSD 2010


You can write:
location ^~ /uploads
{
    root your_root_directory;
}

This will disable trying to handle files in /uploads with different of
this location.

You can also try:
location ~* /uploads/.*\.php$
{
    return 403;
    error_page 403 /403_error.html;
}

And put it before your location for handling php files. This will
match all php files in uploads directory and it's subdirs and show a
error message.

On Thu, Jun 10, 2010 at 7:59 PM, mindfrost82 <nginx-forum at nginx.us> wrote:
> I have nginx setup with PHP as FastCGI.
>
> On my server, I have a couple of upload (writeable) directories and I want to disable nginx/php from serving php files in those directories (and all subdirectories).
>
> I've tried creating some location rules in nginx, but I can't seem to get it working.
>
> For example, if I have /public_html/uploads
>
> Then I have /usr1, /usr2, /usr3, etc as subdirectories under /uploads...
>
> I want to disable php in the uploads directory and all subdirectories.  Or, if its possible to redirect anyone that tries to access a *.php file in those directories to a HTML error message file...either way.
>
> Thanks!
>
> Posted at Nginx Forum: http://forum.nginx.org/read.php?2,96776,96776#msg-96776
>
>
> _______________________________________________
> nginx mailing list
> nginx at nginx.org
> http://nginx.org/mailman/listinfo/nginx
>



-- 
Boris Dolgov.



More information about the nginx mailing list