Skip Navigation

Nginix Password Protected Site

To lock down an Nginx website with a username and password. 
  1. add the following to your Nginx configuration: auth_basic "Restricted Area"; auth_basic_user_file /home/forge/default/.htpasswd; 
  2. Next, create a .htpasswd in your sites directory. In the example above the site, directory name would be "default". 
  3. You need to md5 your password I suggest using something like this: http://www.htaccesstools.com/htpasswd-generator/
  4. For example, I generated username and password: codetime:$apr1$8v.xDamX$GNzJXTIGcHPyU3CeITxEE1 The username is "codetime", the password, in this case, is also "codetime" but its been md5 hashed.
  5. Paste it into the .htpasswd file and then save.
  6. You may need to restart your server/nginx
location / {
  try_files $uri $uri/ /index.php?$query_string;
  # require password to access site
  auth_basic            "Restricted Area";
  auth_basic_user_file  /home/forge/default/.htpasswd;
}

Related Snippets

See all