Password protecting folders or resource with Nginx

All you need to do is add the following two entries in the location listing in the server conf settings (ngnix.conf) file.

location = / {
    auth_basic "Restricted";
    auth_basic_user_file /path/to/htpasswd;

    ...
 }

Go to /opt/nginx/conf/ and run below command, make sure that htpasswd file is present in that directory.

htpasswd -c -b htpasswd <user> <pass> 

Leave a comment