Skip to content

Instantly share code, notes, and snippets.

@akirattii
Created June 23, 2017 03:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save akirattii/3fec706db572c35dd12185cb3a4c038c to your computer and use it in GitHub Desktop.
Save akirattii/3fec706db572c35dd12185cb3a4c038c to your computer and use it in GitHub Desktop.
Super easy way of Basic Authenticatoin setup of nginx

Simple Basic Authentication setup for nginx:

$ sudo apt-get install nginx

$ sudo sh -c "echo -n '<username>:' >> /etc/nginx/.htpasswd"
$ sudo sh -c "openssl passwd -apr1 >> /etc/nginx/.htpasswd"
Password: <password>
Verifying - Password: <password>

$ sudo nano /etc/nginx/sites-enabled/default 
server {
	...
    location / {
    	...
    	# BASIC Auth:
        auth_basic "Restricted Content";
        auth_basic_user_file /etc/nginx/.htpasswd;
    }
}

$ sudo service nginx restart
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment