【问题标题】:Passenger reading .htaccess from outside rails documentroot乘客从外部 rails documentroot 读取 .htaccess
【发布时间】:2026-01-28 18:55:02
【问题描述】:

我有一个在 apache2+phusion_passenger 上运行的 rail3 应用程序。直到几天前我突然开始收到以下错误时,一切都运行得非常顺利:

[Mon May 13 11:43:16 2013] [error] [client 54.228.16.0] Request exceeded the limit of 10 internal redirects due to probable configuration error. Use 'LimitInternalRecursion' to increase the limit if necessary. Use 'LogLevel debug' to get a backtrace.
[Mon May 13 11:43:16 2013] [debug] core.c(3063): [client 54.228.16.0] r->uri = /blog/index.php
[Mon May 13 11:43:16 2013] [debug] core.c(3069): [client 54.228.16.0] redirected from r->uri = /blog/index.php
[Mon May 13 11:43:16 2013] [debug] core.c(3069): [client 54.228.16.0] redirected from r->uri = /blog/index.php
[Mon May 13 11:43:16 2013] [debug] core.c(3069): [client 54.228.16.0] redirected from r->uri = /blog/index.php
[Mon May 13 11:43:16 2013] [debug] core.c(3069): [client 54.228.16.0] redirected from r->uri = /blog/index.php
[Mon May 13 11:43:16 2013] [debug] core.c(3069): [client 54.228.16.0] redirected from r->uri = /blog/index.php
[Mon May 13 11:43:16 2013] [debug] core.c(3069): [client 54.228.16.0] redirected from r->uri = /blog/index.php
[Mon May 13 11:43:16 2013] [debug] core.c(3069): [client 54.228.16.0] redirected from r->uri = /blog/index.php
[Mon May 13 11:43:16 2013] [debug] core.c(3069): [client 54.228.16.0] redirected from r->uri = /blog/index.php
[Mon May 13 11:43:16 2013] [debug] core.c(3069): [client 54.228.16.0] redirected from r->uri = /blog/index.php
[Mon May 13 11:43:16 2013] [debug] core.c(3069): [client 54.228.16.0] redirected from r->uri = /index.php

这是我的 apache vhost 配置的样子:

<VirtualHost *:80>
    ServerAdmin "webmaster@xyz.com"
    ServerName analytics.xyz.com
    ServerAlias www.analytics.xyz.com
    MIMEMagicFile /dev/null
    CustomLog logs/analytics_access.log  "%t %>s %b %D %h \"%r\" %u \"%{Referer}i\" \"%{User-Agent}i\""
    ErrorLog logs/analytics_error.log
    LogLevel debug

    DocumentRoot "/home/sysadmin/analytics/public"
    <Directory "/home/sysadmin/analytics/public">
        AllowOverride All
        Options -MultiViews
    </Directory>

</VirtualHost>

经过一番摸索后,我发现.htaccess 位于/home/sysadmin 中,导致了这个问题。我删除了这个文件,一切又开始工作了。

现在这是我的问题。为什么 apache/passenger 正在读取不在 documentroot 中的 .htaccess 文件。系统上还有其他虚拟主机都指向目录 /home/sysadmin/specific_dir 但没有指向 /home/sysadmin/。

另一件事是,即使我将相同的 .htaccess 文件放在类似的位置,我也不会在本地计算机上收到相同的错误。

【问题讨论】:

    标签: ruby-on-rails ruby-on-rails-3 apache passenger


    【解决方案1】:

    首先,感谢您的帖子。这促使我尝试重命名主目录中的 .htaccess,我遇到的问题得到了解决。

    我现在在主目录的.htaccess文件中设置了一个重写条件,如下所示。

    RewriteCond %{HTTP_HOST} !subdomain.example.com
    

    你遇到的问题可以用http://httpd.apache.org/docs/2.2/mod/directive-dict.html#Context中的“上下文”来解释

    【讨论】: