I have a whitelist of IPs for nginx, but in addition to this I want to require basic authentication for specific IP.

For example, allow access for these IPs:

require basic authentication for this IP:

and deny for anyone else.

How is this possible? satisfy directive doesn't seem to solve this problem

1 Answer 1


You could implement this with the GEO directive: http://nginx.org/en/docs/http/ngx_http_geo_module.html#geo

Just a sketch using your ip address examples:

geo $authentication {
default "Authentication required"; "off"; "off"; "on";

server { ... location / { satisfy any;

# basic auth referencing to geo with $authentication auth_basic $authentication; auth_basic_user_file /etc/nginx/.htpasswd; # whitelist for the inital ip address restrictions include /etc/nginx/conf.d/ip-whitelist.conf.include; deny all; }}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.