Nginx Password Protect a website

nginx password protect

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

apt install apache2-utils -y

Now create a password file with command

htpasswd -c /etc/nginx/.htpasswd  USER_NAME_HERE

It will ask for password.

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

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

Restart Nginx.

systemctl restart nginx

Now on visiting the web site, you will be asked to enter username and password.

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

See Nginx

Need help with Linux Server or WordPress? We can help!

Leave a Reply

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