简体   繁体   English

Nginx - 阻止除 index 之外的所有 *.php 文件

[英]Nginx - block all *.php files except index

I'm new to nginx.我是 nginx 的新手。 I need to block all .php files for security reasons.出于安全原因,我需要阻止所有 .php 文件。 Any simple way to do it simmilar to Apache's .htaccess, as below:任何与 Apache 的 .htaccess 类似的简单方法,如下所示:

RewriteCond %{REQUEST_FILENAME} -f
RewriteCond %{REQUEST_FILENAME} \.php$
RewriteRule !^index.php index.php [L,NC]

Thanks in advance!提前致谢!

Instead of usual nginx PHP handler location而不是通常的 nginx PHP 处理程序位置

location ~ \.php$ {
    ... # FastCGI PHP handler here
}

use something like使用类似的东西

location ~ \.php$ {
    rewrite ^ /index.php last;
}
location = /index.php {
    ... # FastCGI PHP handler here
}

Although regex matching locations ( location ~ <regex> { ... } ) are taking priority over the prefix locations ( location <URI prefix> { ... } ) on the request URI match, exact matching location ( location = <URI> { ... } ) are taking priority over both of them.尽管正则表达式匹配位置( location ~ <regex> { ... } )在请求 URI 匹配上优先于前缀位置( location <URI prefix> { ... } ),但精确匹配位置( location = <URI> { ... } ) 优先于它们两者。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM