Passenger and nginx Maintenance Page

I recently had the pleasure of moving a Rails app from Apache/Passenger based system to an nginx/Passenger system, deployed by Capistrano. In Apache, I had a setup where I could take a production site down for maintenance by touching ‘tmp/stop.txt’ and using the following directive in my VirtualHost (courtesy of Otto Hilska at Nodeta):

<VirtualHost *:80>
	ServerName www.example.com
	DocumentRoot /u/apps/example/current/public
	ErrorDocument 503 /maintenance.html
	RewriteEngine on
	RewriteCond %{DOCUMENT_ROOT}/../tmp/stop.txt -f
	RewriteCond %{DOCUMENT_ROOT}/%{REQUEST_FILENAME} !-f
	RewriteCond %{SCRIPT_FILENAME} !maintenance.html
	RewriteRule ^(.*)$ /$1 [R=503,L]

	<Directory /u/apps/example/current/public>
		RailsEnv production
		Options -MultiViews
		AllowOverride None
		Order allow,deny
		allow from all
	</Directory>
</VirtualHost>

This worked perfectly, and allowed me to use images/css/etc on my error documents without them being redirected to 503s as well. Based on Eli Miller’s solution, I was able to write something similar for my nginx server config:

server {
	listen 80;
	server_name www.example.com;
	error_page 503 /maintenance.html;
	root /u/apps/example/current/public;
	passenger_enabled on;
	rails_env production;

	# If the maintenance stop file exists
	if (-f $document_root/../tmp/stop.txt) {
		set $maintenance 1;
	}

	# If the request exists as a static file in public
	if (-f $document_root/$uri) {
		set $maintenance 0;
	}

	if ($maintenance) {
		return 503;
	}
}

I was able to test this successfully with nginx 0.7.67 and 0.8.53, and Passenger 2.2.15 and 3.0.1. If you know a better/clearer way to do this, please share!

Posted in Development, Ruby on Rails | Tagged , , , | 1 Comment

Lighttpd + Mongrel + Rails + Windows

I recently worked on a project that required me to host a rails application on Windows XP Home, something I had no experience with but took on as our options were limited. We wanted a load-balanced server running a Rails app with a MySQL database. An XAMPP install was also being used by another group on the server, through which we had MySQL access.

I learned quite a bit trying to get it working, and I hope I can help someone else with how I did it. I started this last fall, so some of the software may have been updated. Also, I would like to thank Joseph Jaramillo for his post on Deploying to IIS with lighttpd and Mongrel which was a huge help setting this up.

Continue reading

Posted in Local Talk, Ruby on Rails | Tagged , , , | 3 Comments

Cut Wifi Login Times (University of Calgary)

Those at the University of Calgary with laptops know that there is a public wireless network available for students. It’s unencrypted, but requires a login through a portal before internet services are provided. I found that whenever I moved between classes or left my laptop off for more than half an hour, I had to login again, which is not very efficient if you have to do it five times a day. What if you only had to do it once? What if you had a program to do it automatically for you?

Someone undoubtedly thought of this, and created Devicescape. A multi-platform application that will automatically log you into (certain) wireless networks, one of which is the UofC network. It’s simple to use, just hop over to their site and download the Devicescape client. Sign up for an account, load up your airUC credentials, and the program will do the rest. As soon as your device connects to airUC, Devicescape will login within seconds, allowing you to skip loading the login page in your browser.

One of the best parts is how well it integrates with your OS. On OS X, it sits in the menubar and notifies you when it is logged in or out. No dialogs, no preference pane, no clunky application. It also runs on most mobile devices, take a look at the list to see if yours is supported. Be sure to also check that the networks you want to connect to are supported as well.

Posted in University | Tagged , , | Leave a comment