Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Nginx - Password Protect Not Working

Tags:

nginx

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.

like image 979
J.Zil Avatar asked Sep 17 '12 22:09

J.Zil


People also ask

What is Auth_basic in nginx?

auth_basic. auth_basic_user_file. The ngx_http_auth_basic_module module allows limiting access to resources by validating the user name and password using the “HTTP Basic Authentication” protocol. Access can also be limited by address, by the result of subrequest, or by JWT.

What is nginx default username and password?

login nginx admin ui default user/password is admin / admin , password change is required after first login.


1 Answers

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

like image 181
Aman Avatar answered Sep 22 '22 11:09

Aman