Nginx Password Protect a website

nginx password protect

To password protect a website, you need to install htpasswd utility. On Ubuntu/Debian, you can install it with the command

apt install apache2-utils -y

Now create a password file with the command

htpasswd -c /etc/nginx/.htpasswd  USER_NAME_HERE

It will ask for a password.

Edit the configuration file for your website and add the following in the server entry for the website.

auth_basic "Members Only";
auth_basic_user_file /etc/nginx/.htpasswd;

Restart Nginx.

systemctl restart nginx

Now on visiting the website, you will be asked to enter your username and password.

If you need to allow SSL renewals, then see SSL Renewal On Nginx Password Protected site

See Nginx

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *