我有一台在Apache上运行3个站点的Linux服务器。我们称之为RailsApp1,RailsApp2和SimpleApp。两个Rails应用程序都使用Mongrel群集。另一个应用程序只是一个HTML文件。我在Apache中为每个站点设置了不同的虚拟主机文件,以及两个Rails站点的mongrel_cluster.yml文件(所有代码均位于底部)。在Apache和Mongrel上为Rails应用程序设置虚拟主机
随着一切设置,我可以启用在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