首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在Apache和Mongrel上为Rails应用程序设置虚拟主机

在Apache和Mongrel上为Rails应用程序设置虚拟主机
EN

Stack Overflow用户
提问于 2010-09-08 17:20:20
回答 1查看 1.8K关注 0票数 1

我有一个Linux服务器在Apache上运行3个站点。让我们叫他们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文件:

代码语言:javascript
复制
<VirtualHost *:80>
  ServerName www.simpleapp.com
  ServerAlias simpleapp.com
  DocumentRoot /home/nudecanaltroll/public_html/simpleapp
</VirtualHost>

RailsApp1 1的VHOST文件:

代码语言:javascript
复制
<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 2的VHOST文件:

代码语言:javascript
复制
<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 1的mongrel_cluster.yml文件:

代码语言:javascript
复制
---
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 2的mongrel_cluster.yml文件:

代码语言:javascript
复制
---
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
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2010-09-12 08:23:14

我想通了。由于我不知道的原因,我需要将ServerAlias设置为RailsApp2,并添加“www”。在ServerName前面。因此,railsapp2.com vhost文件的顶部现在看起来如下所示:

代码语言:javascript
复制
<VirtualHost *:80>
  ServerName www.railsapp2.com
  ServerAlias railsapp2.com
  ...

由于某些原因,RailsApp1不需要这些更改才能正常工作。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/3670273

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档