This article mainly introduces the method of Apache Nginx to prohibit the execution of PHP script files in a directory. The content is quite good. I will share it with you now and give it as a reference.
When we build a website, we may need to set permissions on some directories separately to achieve the security effects we need. The following is an example of how to prohibit the execution of php files in a certain directory under Apache or Nginx.
1.Apache configuration
<Directory /apps/web/renwole/wp-content/uploads> php_flag engine off </Directory> <Directory ~ "^/apps/web/renwole/wp-content/uploads"> <Files ~ ".php"> Order allow,deny Deny from all </Files> </Directory>
2.Nginx configuration
location /wp-content/uploads { location ~ .*\.(php)?$ { deny all; } }
Nginx prohibits multiple directories from executing PHP:
location ~* ^/(css|uploads)/.*\.(php)${ deny all; }
After the configuration is completed, reload the configuration file or restart the Apache or Nginx service. All subsequent PHP files accessed through uploads will return 403, which greatly increases the security of the web directory.
The above is the entire content of this article. I hope it will be helpful to everyone's study. For more related content, please pay attention to the PHP Chinese website!
Related recommendations:
The above is the detailed content of How to prevent directory execution of PHP script files by Apache Nginx. For more information, please follow other related articles on the PHP Chinese website!