首页 > 解决方案 > 在不提供凭据的情况下允许来自 IP 的请求访问 Nginx 失败

问题描述

我正在尝试实现Nginx 白名单,即允许来自某个 IP 地址的用户在不提供凭据的情况下访问 Nginx。
但是,即使我遵循了Nginx 文档,来自该 IP 上的浏览​​器的请求也会受到用户名/密码的挑战(需要 401 身份验证)。

这是我的配置(在 AWS/EC2 CentOS 7 实例上):

[centos@ip-172-31-94-4 nginx]$ cat /etc/nginx/conf.d/default.conf
server {
    location / {
        root   /usr/share/nginx/html;
        index  index.html index.htm;

        satisfy all; 

        # Requests from this IP need not supply a password
        allow 96.53.xx.xx;
        deny all;

        # Others should supply username/passwords
        auth_basic           "Private site";
        auth_basic_user_file /etc/nginx/.htpasswd;
    }

    error_page  404              /404.html;

    # redirect server error pages to the static page /50x.html
    #
    error_page   500 502 503 504  /50x.html;
    location = /50x.html {
        root   /usr/share/nginx/html;
    }

    location ~ /\.ht {
        deny  all;
    }
}

您能否建议如何让来自 96.53.xx.xx 的 Nginx 请求通过而不会受到用户名/密码的挑战?

编辑:
浏览器缓存和历史被清除并sudo nginx -s reload执行。

标签: nginx

解决方案


更改satisfy all为后satisfy any,白名单似乎正在工作。


推荐阅读