Skip to content

Instantly share code, notes, and snippets.

@adriancbo
Last active August 29, 2015 14:05
Show Gist options
  • Save adriancbo/64718448e11a4ee67f8c to your computer and use it in GitHub Desktop.
Save adriancbo/64718448e11a4ee67f8c to your computer and use it in GitHub Desktop.
Steps for simple nginx .htpasswd auth - Ubuntu
1. Get apache utils:
sudo apt-get install apache2-utils
2. Create .htpasswd file and make up a username (one-liner)
sudo htpasswd -c /etc/nginx/.htpasswd exampleuser
3. You will be prompted to enter a new password
4. Copy & paste the following into your etc/nginx/sites-available/yoursite file
server {
listen portnumber;
server_name ip_address;
location / {
root /var/www/mywebsite.com;
index index.html index.htm;
auth_basic "Restricted"; #For Basic Auth
auth_basic_user_file /etc/nginx/.htpasswd; #For Basic Auth # PATH to .htpasswd
}
}
5. Don't forget to activate your site by symlinking if you haven't already:
sudo ln -s /etc/nginx/sites-available/yoursite /etc/nginx/sites-enabled/yoursite
6. Restart nginx:
sudo service nginc restart
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment