我正在尝试在具有两个虚拟主机的 ubuntu 服务器上运行 apache2 实例。一个用于 redmine(phusion 乘客),一个用于 ReviewBoard(mod_wsgi)。我还没有创建允许它们两个都可用的单个服务器配置,并且发生了一些奇怪的事情。
我正在尝试获取 www.domain.com/redmine 和 www.domain.com/reviews。运行时这两个站点的初始化顺序取决于sudo service apache2 restart
我能访问哪个站点。例如,如果我在 apache2.conf 中有:
Include sites-enabled/reviews
Include sites-enabled/redmine
www.domain.com/reviews
将是我能到达的地方,但如果它们颠倒过来,我就能到达www.domain.com/redmine
。
sites-enabled 中的配置如下所示:
#sites-enabled/redmine
<VirtualHost *:80>
ServerName redmine.ts.com
# !!! Be sure to point DocumentRoot to 'public'!
DocumentRoot /var/www/tracking
<Directory /var/www/tracking/redmine>
Order allow,deny
Allow from all
Options -MultiViews FollowSymLinks Indexes
PassengerResolveSymlinksInDocumentRoot on
RailsBaseURI /redmine
</Directory>
</VirtualHost>
#sites-enabled/reviews
<VirtualHost *:80>
ServerName reviews.ts.com
DocumentRoot /var/www/reviews/htdocs
# Error handlers
ErrorDocument 500 /errordocs/500.html
WSGIPassAuthorization On
WSGIScriptAlias "/reviews" "/var/www/reviews/htdocs/reviewboard.wsgi/reviews"
<Directory /var/www/reviews/htdocs>
AllowOverride All
Options -Indexes FollowSymLinks
Allow from all
</Directory>
# Alias static media requests to filesystem
Alias /reviews/media "/var/www/reviews/htdocs/media"
Alias /reviews/errordocs "/var/www/reviews/htdocs/errordocs"
Alias /reviews/favicon.ico "/var/www/reviews/htdocs/media/rbcommons/images/favicon.png"
</VirtualHost>
有人知道为什么这两个站点会根据哪个先初始化而互相阻塞吗?这很令人沮丧
答案1
您需要一个虚拟主机,其下有两个目录才能实现您的目标。两个虚拟主机绑定到 *:80,且 ServerName 设置不同,这将导致两个单独的命名虚拟主机,并且 URL 将不位于一个主机下。
这应该通过指向您已列出的目录的别名指令来实现。根据您的两个配置文件,它应该大致如下所示。
<VirtualHost *:80>
ServerName www.domain.com
# Set a default root
DocumentRoot /var/www/html
# Define redmine subfolder and directory settings
Alias /redmine /var/www/tracking/redmine
<Directory /var/www/tracking/redmine>
Order allow,deny
Allow from all
Options -MultiViews FollowSymLinks Indexes
PassengerResolveSymlinksInDocumentRoot on
RailsBaseURI /redmine
</Directory>
# These settings may need to be moved under the directory definiton
WSGIPassAuthorization On
WSGIScriptAlias "/reviews" "/var/www/reviews/htdocs/reviewboard.wsgi/reviews"
<Directory /var/www/reviews/htdocs>
AllowOverride All
Options -Indexes FollowSymLinks
Allow from all
</Directory>
Alias /reviews/media "/var/www/reviews/htdocs/media"
Alias /reviews/errordocs "/var/www/reviews/htdocs/errordocs"
Alias /reviews/favicon.ico "/var/www/reviews/htdocs/media/rbcommons/images/favicon.png"
</VirtualHost>