我有一个在 Apache 上运行 3 个站点的 Linux 服务器。我们称它们为 RailsApp1、RailsApp2 和 SimpleApp。两个 Rails 应用程序都使用 Mongrel 集群。另一个应用程序只是一个 HTML 文件。我在 Apache 中为每个站点设置了不同的虚拟主机文件,以及两个 Rails 站点的 mongrel_cluster.yml 文件(所有这些的代码都在底部)。
完成所有设置后,我就可以在 Apache 中启用这些站点了。而且我可以很好地为每个 Rails 站点启动 Mongrel 集群。而且,事实上,在我的浏览器中访问 www.simpleapp.com 和 www.railsapp1.com 就可以了。但是,www.railsapp2.com 给我带来了很多麻烦。服务器不显示 railsapp2 的代码,而是返回 railsapp1 的 HTML。如果我在 Apache 中禁用 railsapp1,然后访问 www.railsapp2.com,服务器现在会返回 simpleapp 的 HTML。只有当我在 Apache 中同时禁用 railsapp1 和 railsapp2 时,服务器才会正确响应 www.railsapp2.com 上的请求。
关于为什么会发生这种情况的任何想法?
SimpleApp 的 VHOST 文件:
<VirtualHost *:80>
ServerName www.simpleapp.com
ServerAlias simpleapp.com
DocumentRoot /home/nudecanaltroll/public_html/simpleapp
</VirtualHost>
RailsApp1 的 VHOST 文件:
<VirtualHost *:80>
ServerName railsapp1.com
DocumentRoot /home/nudecanaltroll/public_html/railsapp1/public
RewriteEngine On
<Proxy balancer://mongrel1>
BalancerMember http://127.0.0.1:5000
BalancerMember http://127.0.0.1:5001
BalancerMember http://127.0.0.1:5002
</Proxy>
# Timeout in 30 seconds
ProxyTimeout 30
# Make sure people go to www.railsapp1.com, not railsapp1.com
RewriteCond %{HTTP_HOST} ^railsapp1\.com$ [NC]
RewriteRule ^(.*)$ http://www.railsapp1.com$1 [R=301,NE,L]
# Redirect all non-static requests to thin
RewriteCond %{DOCUMENT_ROOT}/%{REQUEST_FILENAME} !-f
RewriteRule ^/mongrel1(.*)$ balancer://mongrel1%{REQUEST_URI} [P,QSA,L]
# Proxy Stuff
ProxyPass / balancer://mongrel1/
ProxyPassReverse / balancer://mongrel1/
ProxyPreserveHost on
<Proxy *>
Order deny,allow
Allow from all
</Proxy>
# Custom log file locations
ErrorLog /home/nudecanaltroll/public_html/railsapp1/log/error.log
CustomLog /home/nudecanaltroll/public_html/railsapp1/log/access.log combined
</VirtualHost>
RailsApp2 的 VHOST 文件:
<VirtualHost *:80>
ServerName railsapp2.com
DocumentRoot /home/nudecanaltroll/public_html/railsapp2/public
RewriteEngine On
<Proxy balancer://mongrel2>
BalancerMember http://127.0.0.1:6000
BalancerMember http://127.0.0.1:6001
BalancerMember http://127.0.0.1:6002
</Proxy>
# Timeout in 30 seconds
ProxyTimeout 30
# Make sure people go to www.railsapp2.com, not railsapp2.com
RewriteCond %{HTTP_HOST} ^railsapp2\.com$ [NC]
RewriteRule ^(.*)$ http://www.railsapp2.com$1 [R=301,NE,L]
# Redirect all non-static requests to thin
RewriteCond %{DOCUMENT_ROOT}/%{REQUEST_FILENAME} !-f
RewriteRule ^/mongrel2(.*)$ balancer://mongrel2%{REQUEST_URI} [P,QSA,L]
# Proxy Stuff
ProxyPass / balancer://mongrel2/
ProxyPassReverse / balancer://mongrel2/
ProxyPreserveHost on
<Proxy *>
Order deny,allow
Allow from all
</Proxy>
# Custom log file locations
ErrorLog /home/nudecanaltroll/public_html/railsapp2/log/error.log
CustomLog /home/nudecanaltroll/public_html/railsapp2/log/access.log combined
</VirtualHost>
RailsApp1 的 mongrel_cluster.yml 文件:
---
address: 127.0.0.1
log_file: log/mongrel.log
port: 5000
cwd: /home/nudecanaltroll/public_html/railsapp1
environment: production
pid_file: /home/nudecanaltroll/public_html/railsapp1/tmp/pids/mongrel.pid
servers: 3
RailsApp2 的 mongrel_cluster.yml 文件:
---
address: 127.0.0.1
log_file: log/mongrel.log
port: 6000
cwd: /home/nudecanaltroll/public_html/railsapp2
environment: production
pid_file: /home/nudecanaltroll/public_html/railsapp2/tmp/pids/mongrel.pid
servers: 3