Home > Backend Development > PHP Problem > How to set nginx to prohibit parsing php files

How to set nginx to prohibit parsing php files

王林
Release: 2023-03-05 20:46:01
Original
3062 people have browsed it

nginx sets the method to prohibit parsing PHP files: PHP parsing can be restricted based on the directory. Specific method: First open the configuration file; then find the configuration [location ~ .php$] and set it to [deny all].

How to set nginx to prohibit parsing php files

Specific method:

(Recommended tutorial: nginx tutorial)

Restrict php parsing

Restrict php parsing based on directory:

location ~ .*(diy|template|attachments|forumdata|attachment|image)/.*\.php$
{
    deny all;
}
Copy after login

Restrict browser access

Use user_agent to control client browser access

location / {
    if ($http_user_agent ~ 'bingbot/2.0|MJ12bot/v1.4.2|Spider/3.0|YoudaoBot|Tomato|Gecko/20100315'){
            return 403;
    }
}
Copy after login

Related recommendations: php training

The above is the detailed content of How to set nginx to prohibit parsing php files. 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