Home > Backend Development > PHP Tutorial > How to prevent directory execution of PHP script files by Apache Nginx

How to prevent directory execution of PHP script files by Apache Nginx

不言
Release: 2023-04-01 16:46:01
Original
1624 people have browsed it

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

2.Nginx configuration

location /wp-content/uploads {
  location ~ .*\.(php)?$ {
  deny all;
  }
}
Copy after login

Nginx prohibits multiple directories from executing PHP:

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

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:

How to use PHP to forge a referer to break through the network disk and prohibit external connections

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!

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