NGINX Protect Domain through Password

NGINX Protect Domain through Password

It’s very easy to place a simple htpasswd-based authentication system on a domain served by nginx. To do this, you’ll want your server block to look like this:

The relevant lines here are the last two defining auth_basic and auth_basic_user_file. Notice that the file is /etc/nginx/htpasswd. This means you need to use htpasswd to create that file:

Adding users without overriding the existing contents :

Now when you visit your domain, you will be asked to enter a username and password that you chose beforehand. This is definitely not the most secure way of restricting domain access, but it’s something. Check out htpasswd’s help for more secure options:

NGINX Overall Configuration Site

Leave a Reply

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