![如何保护对我网站根目录下特定 php 文件的访问](https://linux22.com/image/595629/%E5%A6%82%E4%BD%95%E4%BF%9D%E6%8A%A4%E5%AF%B9%E6%88%91%E7%BD%91%E7%AB%99%E6%A0%B9%E7%9B%AE%E5%BD%95%E4%B8%8B%E7%89%B9%E5%AE%9A%20php%20%E6%96%87%E4%BB%B6%E7%9A%84%E8%AE%BF%E9%97%AE.png)
我想限制访问(并且仅限于)http://mysite.com/protected.php使用 nginx。我可以尝试什么?目前,我设法做到了这一点,但 php 文件不再由 php-fpm 解释。
location ~ \.php($|/) {
location ~ ^/ws(_dev)?\.php {
auth_basic "User synchronisation webservice > please login";
auth_basic_user_file /home/symfony/instances/somesite/ws_access;
}
set $script $uri;
set $path_info "";
if ($uri ~ "^(.+\.php)(/.*)") {
set $script $1;
set $path_info $2;
}
add_header X-Response-Host somesite.com;
fastcgi_pass 127.0.0.1:8300;
include /etc/nginx/fastcgi_params;
fastcgi_param SCRIPT_FILENAME /home/symfony/instances/somesite/service/web$script;
fastcgi_param PATH_INFO $path_info;
fastcgi_param SCRIPT_NAME $script;
fastcgi_param SERVER_PORT "80";
}
答案1
您需要fastcgi_*
在新的location /protected.php
块中重复指令。