gpt4 book ai didi

ruby-on-rails - 在 Apache 和 Mongrel 上为 Rails 应用设置虚拟主机

转载 作者:塔克拉玛干 更新时间:2023-11-03 01:40:58 25 4
gpt4 key购买 nike

我有一个 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 文件:

<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

最佳答案

我想通了。由于我不知道的原因,我需要为 RailsApp2 设置 ServerAlias,并添加“www”。在服务器名称前面。所以 railsapp2.com vhost 文件的顶部现在看起来像这样:

<VirtualHost *:80>
ServerName www.railsapp2.com
ServerAlias railsapp2.com
...

出于某种原因,RailsApp1 不需要这些更改即可正常运行。

关于ruby-on-rails - 在 Apache 和 Mongrel 上为 Rails 应用设置虚拟主机,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3670273/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com