文档: satisfy
参数 all 表示,所有条件都得满足;
参数 any 表示,任一条件满足即可。
所包含的条件包括 ngx_http_access_module, ngx_http_auth_basic_module, ngx_http_auth_request_module, 和 ngx_http_auth_jwt_module 这4个模块。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
satisfy any; deny 192.168.1.1/32; allow 192.168.1.0/24; deny all; auth_basic "auth required"; auth_basic_user_file /etc/nginx/external.passwd; location @auth_failure { if ($http_authorization != "") { rewrite ^ http://sskaje.me/error.html redirect; } } error_page 401 = @auth_failure; |
上述配置还处理了认证失败的跳转。
这个配置可以保存成独立的 .conf 文件,在 server {} 里 include。
Nginx 特定 IP 需要认证 by @sskaje: https://sskaje.me/2017/01/nginx-requires-auth-for-some-certain-ip/
Link to this post!