nginxnginx-configwebsecurity

Disable PHP Execution in a directory (using Nginx)


I came across solutions to block executables but only by using .htaccess file in the directory.

# Block executables
<FilesMatch "\.(php|phtml|php3|php4|php5|pl|py|jsp|asp|html|htm|shtml|sh|cgi|suspected)$">
    deny from all
</FilesMatch>

How can I achieve the same thing if I only have Nginx and not apache2 ?


Solution

  • The block for Nginx will be as follows. This rule implies that file with any extension in the below list will not be executed.

    location /home/username/public_html/wp-content/uploads {
        location ~* \.(php|phtml|php3|php4|php5|pl|py|jsp|asp|html|htm|shtml|sh|cgi|suspected)$ {
            deny all;
        }
    }