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

How to set nginx to prohibit parsing php files

王林
王林Original
2020-09-11 15:07:313028browse

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;
}

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;
    }
}

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!

Statement:
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