DGRMM.net

David and Becky's little domain

SCGI Caching and rewriting

Posted by David Morton Thu, 17 Nov 2005 20:47:00 GMT

In the current status of things with SCGI, it is not possible to do caching properly and at the same time do routing/rewriting properly.

If you mount scgi on the root url:


SCGIMount / 127.0.0.1:9999

then all requests are passed into SCGI, and cached pages and static files are not served by the webserver directly. Ack!

The workaround is to mount SCGI on a sub-folder:

SCGIMount /scgi-bin/ 127.0.0.1:9998

and then use mod_rewrite to map things over if the file doesn’t exist:


RewriteRule ^([^.]+)$ $1.html [QSA]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^.*$ /scgi-bin/%{REQUEST_URI} [QSA,L]

But now all your application urls have a /scgi-bin/ prefix on them, so you have to mess with routes to clean it up. A messy business for typo, because it uses quite a few routes.

The solution is a plugin that removes the scgi-bin from the url before rails routing gets ahold of it. It is temporarily available from here. Thanks to Trevor Squires for writing this plugin. His svn repository is available at http://opensvn.csie.org/protocool/trunk/plugins/scgi_bin/

This also happened to cause problems with Typo, as static files that were located in public could not be served; the SCGI engine kept trying to run a rails controller/method which didn’t exist. This caused the admin stylesheet to not be loaded, among other things. By applying this plugin, typo can run directly under SCGI without any modifications1.

1 Except for the .htacess file and apache configs, of course.

1 comment |

  1. http://justbudget.com
    12 days later:

    you could have also rewrite the connect method in the routes.rb file

    like … (not exact, but you’ll see the idea)

    @orig_connect = map.connect map.connect = Proc.new do |route, options| @orig_connect route, options @orig_connect ‘scgi-bin’ + route, options end

    somekool