Py学习  »  NGINX

nginx拒绝对文件夹的所有访问,但php脚本不受规则影响

ProtectedVoid • 4 年前 • 534 次点击  

我正在尝试在我的服务器配置文件中为nginx设置安全指令。我有以下指示:

location /config {
    deny all;
    return 404;
}

该目录中的所有文件都受到限制,但PHP文件不受该指令的影响,我的目的是拒绝所有内容。我假设配置文件中的另一个指令正在覆盖这个指令,但是我在nginx中还是个新手。

这是服务器的完整配置代码:

server{
        listen 80;
        server_name mydomain.com;
        root myrootpath;
        index index.php index.html index.htm;

        include security-directives;

        location ~ \.php$ {
            fastcgi_pass   127.0.0.1:9123;
            fastcgi_index  index.php;
            fastcgi_param  SCRIPT_FILENAME  
            $document_root$fastcgi_script_name;
            include        fastcgi_params;
        }
}

安全指令文件包含第一个代码块中详细说明的指令。

Python社区是高质量的Python/Django开发社区
本文地址:http://www.python88.com/topic/37981
 
534 次点击  
文章 [ 1 ]  |  最新文章 4 年前
Richard Smith
Reply   •   1 楼
Richard Smith    5 年前

正则表达式位置块优先于前缀位置块,因此 .php 规则中不包含文件。

使用 ^~ 使前缀位置优先于正则表达式位置块的修饰符。

例如:

location ^~ /config { 
    return 403; 
}

this document 详情。