Skip to content

Instantly share code, notes, and snippets.

@lihonosov
Created July 2, 2014 19:22
Show Gist options
  • Select an option

  • Save lihonosov/faaec626bf753fd1c849 to your computer and use it in GitHub Desktop.

Select an option

Save lihonosov/faaec626bf753fd1c849 to your computer and use it in GitHub Desktop.
Protecting Folders with Nginx
//Creating .htpasswd
htpasswd -c /var/www/html/admin/.htpasswd username
//Setting up Nginx
server {
listen 80;
server_name domain.com www.domain.com;
location / {
# your normal content
}
location /admin {
auth_basic "Administrator Login";
auth_basic_user_file /var/www/html/admin/.htpasswd;
}
#!!! IMPORTANT !!! We need to hide the password file from prying eyes
# This will deny access to any hidden file (beginning with a .period)
location ~ /\. { deny all; }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment