7

in apache i could have a Satisfy Any directive, allowing access without password from a specified IP.

how to do with nginx?

<Directory /home/www/site1/private>
  AuthUserFile /home/www/site1-passwd
  AuthType Basic
  AuthName MySite
  Require valid-user
  Order allow,deny
  Allow from 172.17.10
  Satisfy any
</Directory>
  • This question is a duplicate of http://serverfault.com/questions/183884/nginx-protect-directory-with-password-except-for-specific-ips – Mark Stosberg May 29 '12 at 15:16

1 Answers1

18

Easy:

location / {
    root /home/www/site1/private;
    satisfy  any;
    allow  172.17.10.0/24;
    deny   all;

    auth_basic            "MySite";
    auth_basic_user_file  /home/www/site1-passwd;
}
alvosu
  • 8,357
  • 24
  • 22
  • Link to the documentation: Combining Basic Authentication with Access Restriction by IP Address: https://docs.nginx.com/nginx/admin-guide/security-controls/configuring-http-basic-authentication/#combining-basic-authentication-with-access-restriction-by-ip-address – Nik Jul 10 '19 at 09:02