password protect the website running on nginx php fpm

On ubuntu system

nginx config file location


Web site root location


htpasswd is installed, if not, do

sudo apt-get install apache2-utils

1. Create users and passwords

sudo htpasswd -c /usr/share/nginx/www/ admin_user
sudo htpasswd  /usr/share/nginx/www/ admin_user2

2. Add these to the nginx config file

auth_basic "Restricted Area”;
auth_basic_user_file /usr/share/nginx/www/;

For example, if the config file is /etc/nginx/sites-available/default, open it

vim /etc/nginx/sites-available/default

Find the “location /“ and add these two lines like this

  location / {
      #some other configurations…
      auth_basic "Restricted Area”;                               
      auth_basic_user_file /usr/share/nginx/www/;

3. Reload nginx configuration and restart nginx

sudo /etc/init.d/nginx reload
sudo service php5-fpm restart

Search within Codexpedia

Custom Search

Search the entire web

Custom Search