The Decider said over 4 years ago permalink Comment? (0)
Tagged: rails mongrel ruby nginx

Protect Staging Server with Password

When developing a new application and releasing often you may want to protect the site from prying eyes. A simple way to do this when using the nginx web server is to use basic http authentication.

I prefer to do this in the nginx config file so it doesn’t impact local development.

You’ll need to create a password file using htpasswd command line utility. This file should be relative to the install directory of nginx. The default install would place this file in /usr/local/nginx

sudo htpasswd -cb /usr/local/this_hosts_password_file username password

Next, you need to tell nginx to use basic auth for any access to this (virtual) host. I place the 2 relevant lines in the server portion of the config file

server { listen 80;

  1. auth_basic “Login to see this alpha site.”;
    auth_basic_user_file this_hosts_password_file;

  2. }

A login will now be presented for any entry into the site.

Comments

simple_captcha.jpg
Are you a Human? Type the code above.