Home >Operation and Maintenance >Nginx >What is the method for nginx to prohibit running php scripts in a specified directory?
The way nginx prohibits running php scripts in a specified directory is to directly match the location conditions and then prohibit permissions, such as [location ~* ^/uploads/.*\.(php|php5)${ deny all;}].
#Permission is prohibited after matching the location condition directly.
(Learning video recommendation: java course)
Add the following configuration in the server configuration section
If it is a single directory
location ~* ^/uploads/.*\.(php|php5)$ { deny all; }
If there are multiple directories
location ~* ^/(attachments|uploads)/.*\.(php|php5)$ { deny all; }
Note: This configuration file 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; }
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 the configuration is completed, Nginx needs to be restarted to take effect.
Related recommendations: php training
The above is the detailed content of What is the method for nginx to prohibit running php scripts in a specified directory?. For more information, please follow other related articles on the PHP Chinese website!