Thursday, December 27, 2007

A small pitfall on Mac with Capistrano's deploy:web:disable task

To test a deployment process of a rails application at my local machine, a Mac OS X Leopard, I set up virtual host with Apache + reverse proxy + mongrel. When I tried to do "cap deploy:web:disable", I fell in to a pitfall, a Mac OS X local issue. The apache constantly respond "403 forbidden" for every URL under the virtual host.

The things is...

  1. Capistrano uses "/system/maintenance.html" for the path to the maintenance page (by the default)

  2. And if you use Apache mod_rewrite, the setting about maintenance.html may look like this:

    RewriteCond %{DOCUMENT_ROOT}/system/maintenance.html -f
    RewriteCond %{SCRIPT_FILENAME} !maintenance.html
    RewriteRule ^.*$ /system/maintenance.html [L]

  3. But, "RewriteRule" searchs the root of the file-system for "/system/maintenance.html" first (See description about "URL-path" of RewriteRule)

  4. Yes, there is the directory "/System" on Mac OS X, and HFS+ doesn't matter case of filename

  5. "/System" aren't accessible with httpd except you are mad

  6. So, you get "403 Forbidden"


A alternative of the rewrite rule is:

RewriteRule ^.*$ %{DOCUMENT_ROOT}/system/maintenance.html [L]

It works on Mac OS X (and other systems as well I think).

No comments: