Question

On a server there is already a site running. I'm trying to make my rails app run on a url of the same site i.e the site is example.com and the rails app will run at example.com/railsapp.

The rails app will use passenger and the server is ubuntu. The current virtualhosts file looks like;

<VirtualHost *:80>
    DocumentRoot /var/www
    <Directory />
        Options FollowSymLinks
        AllowOverride All
    </Directory>
    <Directory /var/www/>
        Options Indexes FollowSymLinks MultiViews
        AllowOverride None
        Order allow,deny
        allow from all
    </Directory>
    <Directory /var/www/examplesite/>
                Options Indexes FollowSymlinks Multiviews
                AllowOverride All
                Order allow,deny
                allow from all
    </Directory>
</VirtualHost>

Do I need to add a separate hosts file?

<VirtualHost *:80> 
 ServerName ??? 
 DocumentRoot /var/www/railsapp/public
 <Directory /var/www/railsapp/public> 
  AllowOverride all 
  # MultiViews must be turned off. 
  Options -MultiViews 
 </Directory> 
</VirtualHost> 

I'm not sure what to do...

Was it helpful?

Solution

The proper solution is documented in the Deploying to a sub URI Passenger documentation:

Suppose that you already have a virtual host:

<VirtualHost *:80>
    ServerName www.phusion.nl
    DocumentRoot /websites/phusion
    <Directory /websites/phusion>
        Allow from all
    </Directory>
</VirtualHost>

And you want your Rails application, located in /websites/rails, to be accessible from the URL http://www.phusion.nl/subapp.

To do this, you need to perform the following:

  1. Set Alias {SUBURI} {PATH TO YOUR APPLICATION'S PUBLIC DIRECTORY}.
  2. Create a <Location /{SUBURI}> block.
  3. Inside the Location block, set PassengerBaseURI /{SUBURI}.
  4. Inside the Location block, set PassengerAppRoot {PATH TO YOUR APPLICATION ROOT}.
  5. Create a <Directory {PATH TO YOUR APPLICATION'S PUBLIC DIRECTORY}> block.
  6. Inside the Directory block, set Allow from all.
  7. Inside the Directory block, disable MultiViews.

Here is an example:

<VirtualHost *:80>
    ServerName www.phusion.nl
    DocumentRoot /websites/phusion
    <Directory /websites/phusion>
        Allow from all
    </Directory>

    # These have been added:
    Alias /subapp /websites/rails/public
    <Location /subapp>
        PassengerBaseURI /subapp
        PassengerAppRoot /websites/rails
    </Location>
    <Directory /websites/rails/public>
        Allow from all
        Options -MultiViews
    </Directory>
</VirtualHost>
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top