Apache2 SCGI setup for Rails
SCGI is a project aiming to replace CGI and FastCGI with a simpler protocol.
I just integrated Zed Shaw’s SCGI Rails Runner into a Rails project I’m working on. Documentation on integrating with Apache2, which I’m using, is still somewhat non-existing, so here are the steps it took me to get things up and running on Debian Sarge:
-
install apache development libraries
apt-get install apache2-threaded-dev
- get the latest SCGI module source and unpack it. Didn’t try the module contained in Sarge, as it is rather old (Version 1.2 being about a year old)
-
build and install the Apache module using apxs:
cd scgi-1.7/apache2
apxs2 -i -c mod_scgi.c
a2enmod scgi
-
create a virtual host configuration for your application:
vi /etc/apache2/sites-available/yourdomain
-
as all necessary configuration is done in the virtual host config, you can safely remove the .htaccess file inside the public directory of your Rails application. Also you can remove all dispatch.* handlers inside public.
-
enable the virtual host and restart Apache after that.
a2ensite yourdomain
-
copy the scgi_rails script to the script directory of your rails app. Run
script/scgi_rails help
for usage instructions
Comments
Wrighty
Is there a more robust method of deciding if a request should go through SCGI rather than checking if there's a period? The .htaccess that ships with rails checks if the request lives on the filesystem and if not then pipes it through rails - could that work in this situation?
jk
I tried using some rewrite rules like the ones used with cgi and fcgi.
I gave up because I couldn't find a way to turn off the SCGIHandler from inside such a Rewrite Rule.
I'd be glad to hear of another solution, too, as this way breaks page level caching for sure.
Wrighty
#in httpd.conf
SCGIMount /scgi-bin/ 127.0.0.1:9999
#in .htaccess, replace the dispatch.(f)cgi line with:
RewriteRule ^(.*)$ /scgi-bin/$1 [QSA,L]
#in routes.rb, double up *each* of your routes as so:
map.connect ':controller/:action/:id'
map.connect 'scgi-bin/:controller/:action/:id'
Synapse