【问题标题】:NGinx Denying all access to folders but PHP scripts are not being affected by ruleNGinx 拒绝对文件夹的所有访问,但 PHP 脚本不受规则影响
【发布时间】:2019-01-27 15:46:37
【问题描述】:

我正在尝试在我的服务器配置文件中为 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;
        }
}

security-directives 文件包含第一个代码块中详述的指令。

【问题讨论】:

    标签: nginx web server configuration backend


    【解决方案1】:

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

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

    例如:

    location ^~ /config { 
        return 403; 
    }
    

    详情请见this document

    【讨论】:

      猜你喜欢
      • 2011-02-09
      • 1970-01-01
      • 2012-11-19
      • 2011-10-26
      • 2012-05-30
      • 2016-03-06
      • 2017-07-22
      • 1970-01-01
      • 2016-03-23
      相关资源
      最近更新 更多