Password protecting nginx

Create a Username/Password which will be stored in ‘useraccess’, a file I just made up.

htpasswd -b -c useraccess username password

-b: allows password in command line rather than prompt
-c: creates new passwd file, or rewrites and appends if the file already exists.

Now in the nginx config, under:

server {
location /protectedlocation {
Add the following

auth_basic "Message box title of password prompt";
auth_basic_user_file /path/to/useraccess;

Now restart nginx and go to the location you've just protected.  Please comment if this was useful.
This entry was posted in Development, nginx, Uncategorized. Bookmark the permalink. Post a comment or leave a trackback: Trackback URL.

Post a Comment

Your email is never published nor shared. Required fields are marked *

*
*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>