From time to time, you might need to protect your website with a username and a password. E.g. if you have a development environment and your don't want it to be publicly accessible.

In this example we'll secure a website named site with username moss and password rocks using HTTP basic auth (the website is run by user user). But first, take a quick look to the basics about fine-tuning your applications with Moss if you haven't done it yet.

Create .htpasswd file

  1. Generate the content of the .htpasswd file for the given username and password. You may use an online htpasswd tool.
  2. Log into your server as user user: ssh user@<server-ip>
  3. Using your favorite text editor, create file /home/user/sites/site/.htpasswd with the content generated in step 1. E.g:
moss:$apr1$DTty1Atw$DubJSGvYhKd4cISIwPGiK0

Nginx configuration

  1. Log into your server as user moss: ssh moss@<server-ip>
  2. Using sudo and your favorite text editor, add the following lines to file /etc/openresty/root_params.site.com:
auth_basic           "restricted site";
auth_basic_user_file /home/user/sites/site/.htpasswd;

Provision your website

  1. Log into Moss
  2. Head to the details of site 
  3. Click the 'Provision' button and wait until Moss finishes the process

Did this answer your question?