Configuring Passenger sub-URIs
Passenger sub-URIs allow you to run multiple Rails aplications under one Apache virtual host, which is great for development. Although Phusion has documented how to do this, I was having trouble. Eventually I got it to work, by doing the steps below:
- The Apache default DocumentRoot location is
/var/www/html. I created a new directory and changed DocumentRoot to/var/www/public - As root,
cd /var/www/public. Add a link to each public directory of each Rails app to be accessed. On Linux, this looks likeln -s /somewhere/MyApp1/public MyApp1, whereMyApp1was created by runningrails MyApp1under the directory/somewhere - Modify the Apache httpd.conf file. DocumentRoot was changed as shown in Step 1. Then add a virtual host block:
<VirtualHost *:80> ServerName 192.168.1.3 DocumentRoot /var/www/public RailsEnv development RailsBaseURI /MyApp1 RailsBaseURI /MyApp2 RailsBaseURI /MyApp3 ErrorLog /var/log/localhost-error_log </VirtualHost>ServerName can also be
localhostorwww.mywebsite.comYou can also use Apache’s Directory block to control permissions and the RailsEnv setting for each RailsBaseURI entry - Finally, add one of the next two lines to MyAppn/config/environment.rb:
config.action_controller.asset_host = "192.168.1.3/MyAppn"
or
config.action_controller.relative_url_root = "/MyAppn"The IP address can also be
localhostorwww.mywebsite.com, whatever you used for ServerName