Search code examples
nginxbasic-authentication

Nginx basic_auth


I have settings:

location / {auth_basic "Private zone";auth_basic_user_file /user/.httpasswds;}

and

location index.html {auth_basic off;}

www.myserver.org/index.html works perfect without basic auth dialog,

Index file is index.html, but www.myserver.org or www.myserver.org/ asks password.

How to solve it? Thank you.


Solution

  • You need to accept connections for / and /index.html without authentication.

    index index.html;
    
    location = / { }
    
    location = /index.html { }
    
    location / {
        auth_basic "Private zone";
        auth_basic_user_file /user/.httpasswds;
    }
    

    See this document for details.