SvennD
Nginx basic HTTP authentication
January 29, 2017

Nginx basic HTTP authentication

Posted on January 29, 2017  •  1 minutes  • 131 words  •  Suggest Changes

A short howto, create a basic HTTP authentication on Nginx, Centos 6.8.

Requirements
Installation

First lets get htpasswd, this “manages” the password file and creates users.

yum install httpd-tools

 

The first run you need to create a new .htpasswd file :

htpasswd -c /var/www/html/.htpasswd svennd

This would create the passwd file and a user svennd (you will be prompted for the password)

Next the nginx configuration in the server {} block :

location /my_secret {
        auth_basic "restricted";
        auth_basic_user_file /var/www/html/.htpasswd;
}

To restrict access to my_secret directory. Next is to check if nginx configuration is fine :

# nginx -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful

And reload nginx :

service nginx reload

Bam, that easy !

Support

If you enjoyed this website, consider buying me a Dr. Pepper

Buy me a Dr PepperBuy me a Dr Pepper