【问题标题】:Nginx - Exclude php files from htpasswd on a specified directoryNginx - 从指定目录的 htpasswd 中排除 php 文件
【发布时间】:2015-10-28 04:55:17
【问题描述】:

我的 nginx 指令:

location / {
    index index.html index.php;
    auth_basic "Members Only";
    auth_basic_user_file /var/www/clients/client1/web1/web/.htpasswd_stats;
}

location ~ \.php$ {
    allow 1.2.3.4;
    allow 127.0.0.1;
    deny all;
    auth_basic "Members Only";
    auth_basic_user_file /var/www/clients/client1/web1/web/.htpasswd_stats;

}

location /dir/ {
    auth_basic off;

}

我使用 'auth_basic off' 选项从 htpasswd 检查中排除 'dir' 目录。

当我尝试访问 http://domain/dir/ 时,我看到了除 php 文件之外的所有文件,因为前面的指令要求我进行身份验证。

在 apache 上,我使用“满足任何”选项,但如果我在 nginx 上使用此选项,则对我不起作用或者我放置的站点不正确。

我的目标是当我访问http://domain/dir/ 时,任何文件都没有身份验证。

谢谢!!

【问题讨论】:

    标签: php nginx


    【解决方案1】:

    这是因为您对所有 .php 文件都有单独的 auth_basic

    要将您的.php 文件保存在/dir/ 中,只需添加此位置块并根据您的用例在此块内设置规则

    location ~ /dir/(.+)\.php$ {
         allow 1.2.3.4;
         allow 127.0.0.1;
         deny all;
         auth_basic off;
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-02-07
      • 1970-01-01
      • 2018-05-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多