Blog

Adding Basic Authentication to Your Engine Yard Application

If you've ever had a development site for a client get crawled by search engine spiders and had to deal with the consequences, you know you want to avoid it again in the future. Bunches of 301 redirects, potential public access to new features, changing dev urls, etc.

If you're running on Engine Yard, we've got a simple solution to prevent that from happening. Basic Authentication on your application with Passenger running for a simple user name/password pop-up to prevent spidering.

Here are the steps:


* On your environments dashboard, click the 'SSH' link to bring up terminal (on a Mac)
* Go to the config directory for the app -> 'cd /data/nginx/servers'
* Open the custom.locations.conf file by typing:
'vim [appname]/custom.locations.conf'
* Add in the following code changing out [app
name] in the conf file for your EY application name:
To save the script: 'Esc' then ':wq' to write and quit VIM.
* Create the htpasswd directives changing out [appname]. [username] can be whatever you would like and can remember. Run the following:
htpasswd -c /data/nginx/servers/[appname]/[appname].users [username]
* Enter your desired password when prompted.
* Check your /data/ngingx/servers/[appname].users
file and delete the empty line at the top of the file above your user data if it exists(this was due to a Gentoo bug)
* Restart nginx using:
sudo /etc/init.d/nginx restart
* Revisit your app and you should have the basic authentication pop-up on your site.

Caveats:


* This will persist across deploys
* If this is not working check your "[app_name]/custom.locations.conf" to make sure you don't have comments in front of any lines to prevent face palming when your co-workers point that out.
* We've only tried this with applications running on Passenger.