簡體   English   中英

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

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

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM