search

Monday, March 23, 2015

How to set up authentication for your website with nginx

You can set up basic authentication with nginx to restrict access to your website:

Install httpd-tools package first:
sudo yum install httpd-tools

If you are on Ubuntu install that package:
sudo apt-get install apache2-utils

Add to your nginx config:
server {
...
auth_basic "closed site";
auth_basic_user_file conf/htpasswd;
}

Go to /etc/nginx and create folder conf:
cd /etc/nginx
sudo mkdir conf

Then you need to generate file htpasswd that contains authentication data:
sudo htpasswd -c htpasswd admin

No comments:

Post a Comment