在服务器上已经有一个站点正在运行。我正在尝试让我的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>
我不知道该怎么做......
答案 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应用程序。
为此,您需要执行以下操作:
Alias {SUBURI} {PATH TO YOUR APPLICATION'S PUBLIC DIRECTORY}
。<Location /{SUBURI}>
块。Location
块内,设置PassengerBaseURI /{SUBURI}
。Location
块内,设置PassengerAppRoot {PATH TO YOUR APPLICATION ROOT}
。<Directory {PATH TO YOUR APPLICATION'S PUBLIC DIRECTORY}>
块。Directory
块内,设置Allow from all
。Directory
阻止内,禁用MultiViews
。以下是一个例子:
<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>