我试图拒绝访问我们所有的PHP脚本,除了一个IP以外的所有外部世界。
location / { deny all; allow <one-ip-address>; error_page 403 goodpage.php; try_files $uri $uri/ =404; } location ~ \.php$ { deny all; allow <one-ip-address>; include snippets/fastcgi-php.conf; fastcgi_pass unix:/run/php/php7.0-fpm.sock; } location /goodpage.php { allow all; include snippets/fastcgi-php.conf; fastcgi_pass unix:/run/php/php7.0-fpm.sock; }
然而,无论我做什么,我总是最终限制所有* .php或没有。 安装程序是Ubuntu 16.04,Nginx 1.10.0,在此先感谢。
您需要了解location块的评估顺序。 详情请参阅此文件 。
简单的解决scheme是将前缀位置更改为完全匹配位置。 例如:
location = /goodpage.php { ... }
孤儿指出, deny all; 声明需要在任何更具体的allow声明之后。 详情请参阅此文件 。