jbutko
6/26/2017 - 11:21 AM

Nginx: Restrict web access with basic auth

Nginx: Restrict web access with basic auth

sudo apt-get install apache2-utils

# assign password to "customuser" user 
sudo htpasswd -c /etc/nginx/.htpasswd customuser

# edit nginx conf usually located in /etc/nginx/sites-available/default or /etc/nginx/sites-available/customsite.com.conf
sudo nano /etc/nginx/sites-available/default

location / {
        ...
        auth_basic "Private Property";
        auth_basic_user_file /etc/nginx/.htpasswd;
}

# via https://www.digitalocean.com/community/tutorials/how-to-set-up-basic-http-authentication-with-nginx-on-ubuntu-14-04