[英]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.