TAGS :Viewed: 5 - Published at: a few seconds ago

[ Nginx - Password Protect Not Working ]

I have followed instructions and still I cant password protect my site. This is what my app-nginx.config looks like:

server {
    listen       80;
    server_name  Server_Test;
    auth_basic            "Restricted";
    auth_basic_user_file  /usr/local/nginx/conf/htpasswd;

...

}

Where am I going wrong? I copied and pasted this right from a tutorial site.

Answer 1


Make sure Nginx can access the password file. Paths for the auth_basic_user_file are relative to the directory of nginx.conf. So if your nginx.conf is located in /usr/local/nginx you can change your directive to:

auth_basic_user_file  conf/htpasswd;

and the file must be readable.

This file should be readable by workers, running from unprivileged user. E. g. when nginx run from www you can set permissions as:

chown root:nobody htpasswd_file
chmod 640 htpasswd_file

-- from http://wiki.nginx.org/HttpAuthBasicModule