[英]Nginx - block all *.php files except index
我是 nginx 的新手。 出于安全原因,我需要阻止所有 .php 文件。 任何与 Apache 的 .htaccess 类似的简单方法,如下所示:
RewriteCond %{REQUEST_FILENAME} -f
RewriteCond %{REQUEST_FILENAME} \.php$
RewriteRule !^index.php index.php [L,NC]
提前致谢!
而不是通常的 nginx PHP 处理程序位置
location ~ \.php$ {
... # FastCGI PHP handler here
}
使用类似的东西
location ~ \.php$ {
rewrite ^ /index.php last;
}
location = /index.php {
... # FastCGI PHP handler here
}
尽管正则表达式匹配位置( location ~ <regex> { ... }
)在请求 URI 匹配上优先于前缀位置( location <URI prefix> { ... }
),但精确匹配位置( location = <URI> { ... }
) 优先于它们两者。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.