How to prevent nginx from running php

藏色散人
Release: 2023-03-06 20:12:02
Original
2590 people have browsed it

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.

How to prevent nginx from running php

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;
 
}
Copy after login

If it is multiple directories

location ~* ^/(attachments|uploads)/.*\.(php|php5)$ 
 
{ 
 
deny all; 
 
}
Copy after login

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;
 
}
Copy after login

*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;
 
}
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!