Home >Backend Development >PHP Problem >How to prevent nginx from running php
How to set up nginx to disable running php: first find the server configuration section; then add the configuration "location ~* ^/uploads/.*\.(php|php5)${deny all; in the server configuration section" }" will do.
Recommended: "PHP Video Tutorial"
It is prohibited to run PHP scripts in specified directories under Nginx
Nginx is simpler. It directly matches the location conditions and then prohibits permissions.
Add the following configuration in the server configuration section
If it is a single directory
location ~* ^/uploads/.*\.(php|php5)$ { deny all; }
If it is multiple directories
location ~* ^/(attachments|uploads)/.*\.(php|php5)$ { deny all; }
Note: This configuration file It must be placed in front of the following configuration to take effect.
location ~ \.php$ { fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params; }
*Finally give a complete configuration example
location ~ /mm/(data|uploads|templets)/*.(php)$ { deny all; } location ~ .php$ { try_files $uri /404.html; fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params; }
After completing the configuration, remember to restart Nginx to take effect.
The above is the detailed content of How to prevent nginx from running php. For more information, please follow other related articles on the PHP Chinese website!