Jens Krämer

Apache2 SCGI setup for Rails

 |  scgi, ruby, rails  |  4 comments

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:

AddDefaultCharset utf-8 ServerName www.yourdomain DocumentRoot /your-switchtower-root/current/public ErrorDocument 500 /500.html ErrorDocument 404 /404.html # handle all requests throug SCGI SCGIMount / 127.0.0.1:9999 # matches locations with a dot following at least one more characters, that is, things like *,html, *.css, *.js, which should be delivered directly from the filesystem <LocationMatch \..+$> # don't handle those with SCGI SCGIHandler Off <Directory /your-switchtower-root/current/public/> Options +FollowSymLinks Order allow,deny allow from all

Comments

Wrighty

Thanks for this, I was pulling my hair out yesterday trying to use the set-mount-point-to-404-Document approach which just meant that rails didn't know what to do with requests for /dispatch.scgi and return routing errors.

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

glad this helped you :-)

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

Don't know if you saw this on the rails list but kyle worked out how to get it running almost properly:

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

My scgi server still seems to be getting sent requests for my .css and .js files. I can't seem to work out why. Any ideas?

You can use Markdown here.

For the sake of spam checking any data you submit, including your IP address, will be transferred to the US based Akismet web service (akismet.com). If that's not acceptable for you, you can also reach me by other means.