我正在使用下面的指令来阻止几个文件types的执行
location ~* (\.php$|\.htaccess$|\.git) { deny all; }
我怎样才能允许一个特定的IP地址执行一个PHP脚本?
我尝试了以下来允许执行一个PHP脚本,但不工作..
location ~ ^adminer.php { fastcgi_pass php-fpm:9000; fastcgi_index adminer.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; fastcgi_param PHP_VALUE "error_log=/var/log/nginx/application_php_errors.log"; include fastcgi_params; }
基于ip阻止用户使用ngx_http_access_module描述的“允许 – 拒绝”指令然后你可以添加一个catch all规则,如果你需要的话。
location ~* phpinfo.php { fastcgi_pass 127.0.0.1:9000; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params; allow your.exact.ip/32; deny all; } location ~* \.(?:php|htaccess|git)$ { deny all; }
使用location = /path/to/adminer.php作为你的位置块。 在nginx中=匹配是最高优先级,其他location块之后不匹配。
在你的configuration中,这很可能是你的location块和重叠匹配的顺序,从而阻止它的工作。