我希望Nginx拒绝访问特定的PHP文件,我们把它donotexposeme.php
,但它似乎没有工作,PHP脚本像往常一样运行。 这是我在configuration文件中的内容:
location / { root /var/www/public_html; index index.php; } location ~ \.php$ { fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME /var/www/public_html$fastcgi_script_name; include fastcgi_params; } location /donotexposeme.php { deny all; }
当然,我每次编辑configuration时都会执行sudo service nginx reload
(或restart
)。
nginx确定哪个位置匹配的顺序可以在这里找到:
http://wiki.nginx.org/HttpCoremodulee#location
在任何其他正则表达式之前,使用其中任何一个都将匹配:
location = /donotexposeme.php
要么
location ^~ /donotexposeme\.php
第一个是完全匹配,而后者是正则表达式前缀匹配。