Tags:

    A Complete Guide to Passenger Sub URI Configuration

    I wanted to use Passenger's RailsBaseURI capability so I could simplify managing the server during development. With Passenger installed on my laptop, there's no more extra web services to start and stop, no more fretting over service ports. And with RailsBaseURI sub-URIs there are nice logically mapped URIs that match my development directories (~/Developer/Rails/railsproj1 => http://localhost/railsproj1, ~/Developer/Rails/railsproj2 => http://localhost/railsproj2, etc.).

    It couldn't get sweeter, but sometimes Passenger doesn't work as advertised (not to worry, it's intense development activity compensates). After following Phusion's directions I was getting a 404 not found error. Then I found the solution at Aschan's blog. So here's a complete (for the moment) guide:

    1. Create the symlink from the Rails project's public folder to a location under your document root. I used the ~/Sites folder as my document root. In it, I made the symlink to my Rails project's public folder, like:

    cd ~/Sites
    ln -s /Users/hg/Developer/Rails/railsproj1/public ./railsproj1
    2. Configure the Apache conf file. I edited /etc/apache2/users/hg.conf: (I've bolded the parts worth noting.)
    <VirtualHost *:80>
      ServerName localhost
      DocumentRoot /Users/hg/Sites
      <Directory /Users/hg/Sites>
        AllowOverride All
        Options Indexes FollowSymLinks MultiViews
        Order allow,deny
        Allow from all
      </Directory>
      RailsBaseURI /railsproj1
      RailsEnv development
    </VirtualHost>
    3. So far, this won't work, although Phusion claims it does. Next add this line (courtesy of Ashchan's blog) in your Rails project's environment.rb file:
    config.action_controller.relative_url_root = "/railsproj1"

    Restart Apache and you should be good to go.  Let me know if you have anything to add.