适用于Rails应用程序的Apache VirtualHosts

时间:2014-01-17 18:50:18

标签: ruby-on-rails apache apache2 virtualhost

在服务器上已经有一个站点正在运行。我正在尝试让我的rails应用程序在同一站点的URL上运行,即该站点是example.com,rails应用程序将在example.com/railsapp上运行。

rails应用程序将使用乘客,服务器为ubuntu。 当前的virtualhosts文件看起来像;

<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>

我是否需要添加单独的主机文件?

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

我不知道该怎么做......

1 个答案:

答案 0 :(得分:4)

Deploying to a sub URI乘客文档中记录了正确的解决方案:

假设您已有虚拟主机:

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

并且您希望可以从网址/websites/rails访问位于http://www.phusion.nl/subapp的Rails应用程序。

为此,您需要执行以下操作:

  1. 设置Alias {SUBURI} {PATH TO YOUR APPLICATION'S PUBLIC DIRECTORY}
  2. 创建<Location /{SUBURI}>块。
  3. Location块内,设置PassengerBaseURI /{SUBURI}
  4. Location块内,设置PassengerAppRoot {PATH TO YOUR APPLICATION ROOT}
  5. 创建<Directory {PATH TO YOUR APPLICATION'S PUBLIC DIRECTORY}>块。
  6. Directory块内,设置Allow from all
  7. Directory阻止内,禁用MultiViews
  8. 以下是一个例子:

    <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>