Nginx password protect through htpasswd

Nginx

Create .htpasswd

1
2
3
4
sudo sh -c "echo -n 'username:' >> /etc/nginx/.htpasswd"
sudo sh -c "openssl passwd -apr1 >> /etc/nginx/.htpasswd"

cat /etc/nginx/.htpasswd # username:$apr1$wI1/T0nB$jEKuTJHkTOOWkopnXqC1d1

Update nginx conf

1
2
3
4
5
6
7
8
server {
listen 80;
...
location / {
auth_basic "Restricted Content";
auth_basic_user_file /etc/nginx/.htpasswd;
}
}

Reload Nginx

1
sudo service nginx reload