Quick reminder for NGINX and using HTACCESS for password protecting a file

Obviously this is easy enough to look up on google these days, but I thought I would write it here so I remember where to find it. If it helps anyone else along the way then that is a double bonus as it were.

Nginx
server {
  listen 443 ssl;
  server_name servername;
  client_max_body_size    64M;

  ...
  
  index index.php index.html;

  # The path is relative to the site root, you can
  # also do this to directories, but don't forget to
  # check the fastcgi settings.
  
  location ~ /filename.ext {
    try_files $uri $uri/ =404;
    auth_basic           "Administrator’s Only";
    auth_basic_user_file /path/to/.htpasswd;
  }
}

I hope that helps, it always helps me when I write stuff down anyway 🙂

#peaceout


Comments

Leave a Reply

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.