Apache-2.2

為什麼我的 Apache 處於無限重定向循環中?

  • April 6, 2014

我們目前在 為 IT 設置了一個內部站點it.example.com,該站點託管一個Redmine站點。

我想設置 Apache,以便如果使用者訪問它,kb.example.com它會將他們重定向到http://it.example.com/some/path/to/knowledge-base作為快捷方式。

我在 httpd.conf 的末尾添加了一個<VirtualHost>,現在每當我嘗試訪問主站點 (it.example.com) 時,瀏覽器都會進入無限重定向循環:

http://it.example.com/projects/knowledge-baseprojects/knowledge-baseprojects/knowledge-baseprojects/knowledge-baseprojects/knowledge-baseprojects/knowledge-baseprojects/knowledge-baseprojects/knowledge-baseprojects/knowledge-baseprojects/knowledge-baseprojects/knowledge-baseprojects/knowledge-baseprojects/knowledge-baseprojects/knowledge-baseprojects/knowledge-baseprojects/knowledge-baseprojects/knowledge-baseprojects/knowledge-baseprojects/knowledge-baseprojects/knowledge-base

這是我的httpd.conf

LoadModule passenger_module /usr/lib/ruby/gems/1.8/gems/passenger-4.0.37/buildout/apache2/mod_passenger.so
<IfModule mod_passenger.c>
 PassengerRoot /usr/lib/ruby/gems/1.8/gems/passenger-4.0.37
 PassengerDefaultRuby /usr/bin/ruby
</IfModule>

ServerName it.example.com
ServerAdmin support@example.com
DocumentRoot /var/www/redmine-2.4.3/public
ErrorLog logs/redmine_error_log
SetEnv RAILS_ENV production
SetEnv RailsEnv production

#If you are using mod_fcgid and are going to upload files larger than
#131072 bytes you should consider adding the following line
#that allows to upload files up to 20 mb
MaxRequestLen 20971520

<Directory "/var/www/redmine-2.4.3/public">
   Options Indexes ExecCGI FollowSymLinks -MultiViews
   Order allow,deny
   Allow from all
   AllowOverride all
</Directory>

<VirtualHost *:80>
 ServerName kb.example.com
 Redirect / http://it.example.com/projects/knowledge-base
</VirtualHost>

所以看起來 VirtualHost 被忽略了,並且 kb.example.com 的規則總是有效 - 從而導致無限重定向……

我認為您需要將現有it.example.com定義包裝在一個<VirtualHost>塊中。我認為這是由於沒有 vhost 定義而導致的it.example.comkb.example.com成為預設 vhost。如果找不到合適的虛擬主機,這就是將提供的服務,然後返回到自身…

引用自:https://serverfault.com/questions/586732