Apache-2.2

從 Apache 2.2 升級到 Apache 2.4 後,Wordpress 顯示永久循環重定向

  • July 2, 2015

我今天已經將我的 Apache 2.2 Web 伺服器升級到 2.4,然後一些 Wordpress 安裝開始出現從非 www 到 www 以及從 www 到非 www 的無限循環 :(

刪除 .htaccesss 沒有幫助。

如何解決這個問題?域配置範例:

SetEnvIf X-Forwarded-Proto https HTTPS=1

ServerAdmin webmaster@internet.az.pl

ServerName internet.az.pl

ServerAlias www.internet.az.pl

DocumentRoot "/home/admin2/komputery"

DirectoryIndex index.php index.html index.shtml index.htm index.pl index.py index.cgi index.rb default.htm Default.aspx Default.asp

ScriptAlias /cgi-bin/ "/home/admin2/internet.az.pl/cgi-bin/"

<IfModule mod_fastcgi.c>
       Alias /internet.az.pl.0fake "/home/admin2/komputery/internet.az.pl.0fake"
       #FastCGIExternalServer "/home/admin2/komputery/internet.az.pl.0fake" -host 127.0.0.1:52474 -idle-timeout 300 -pass-header Authorization
       FastCGIExternalServer "/home/admin2/komputery/internet.az.pl.0fake" -socket /opt/configs/php-fpm/sock/admin2.sock -idle-timeout 300 -pass-header Authorization
       AddType application/x-httpd-fastphp .php
       Action application/x-httpd-fastphp /internet.az.pl.0fake
       <Files "internet.az.pl.0fake">
               RewriteCond %{REQUEST_URI} !internet.az.pl.0fake
       </Files>
</IfModule>

<Directory "/home/admin2/komputery/">
       AllowOverride All
       <IfVersion < 2.4>
               Order allow,deny
               Allow from all
       </IfVersion>
       <IfVersion >= 2.4>
               Require all granted
       </IfVersion>
       Options +ExecCGI
       <FilesMatch \.(cgi|pl)$>
               SetHandler cgi-script
       </FilesMatch>
</Directory>

<IfModule mod_php5.c>
       php_admin_value sendmail_path "/usr/sbin/sendmail -t -i"
       php_admin_value sendmail_from "internet.az.pl"
       Include /home/kloxo/client/admin2/prefork.inc
</IfModule>

<Location "/">
       Allow from all
       Options -Indexes -FollowSymlinks +SymLinksIfOwnerMatch

       <IfModule mod_php5.c>
               php_admin_value open_basedir "/home/admin2:/tmp:/usr/share/pear:/var/lib/php/session/:/home/kloxo/httpd/script:/home/kloxo/httpd/disable/:/usr/bin"
       </IfModule>
</Location>

CustomLog "/home/httpd/internet.az.pl/stats/internet.az.pl-custom_log" combined
ErrorLog "/home/httpd/internet.az.pl/stats/internet.az.pl-error_log"

還有httpd.conf:

  ServerTokens Prod

ServerRoot "/etc/httpd"

# MR -- must be disable here because can not overrite! -- importance for proxy-to-apache
# Listen 80

Include conf.modules.d/*.conf

User apache
Group apache

ServerAdmin root@localhost

<Directory />
   AllowOverride none
   Require all denied
</Directory>

DocumentRoot "/var/www/html"

<Directory "/var/www">
   AllowOverride None
   # Allow open access:
   Require all granted
</Directory>

# Further relax access to the default document root:
<Directory "/var/www/html">
   Options Indexes FollowSymLinks
   AllowOverride None
   Require all granted
</Directory>

<IfModule dir_module>
   DirectoryIndex index.html
</IfModule>

<Files ".ht*">
   Require all denied
</Files>

ErrorLog "logs/error_log"

LogLevel error

<IfModule log_config_module>
       ## MR -- change %h to %a to fix mod_remoteip issue
   LogFormat "%a %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined
   LogFormat "%a %l %u %t \"%r\" %>s %b" common

   <IfModule logio_module>
     LogFormat "%a %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\" %I %O" combinedio
   </IfModule>

   CustomLog "logs/access_log" combined
</IfModule>

<IfModule alias_module>
   # Alias /webpath /full/filesystem/path
   ScriptAlias /cgi-bin/ "/var/www/cgi-bin/"
</IfModule>

<Directory "/var/www/cgi-bin">
   AllowOverride None
   Options None
   Require all granted
</Directory>

<IfModule mime_module>
   TypesConfig /etc/mime.types

   AddType application/x-compress .Z
   AddType application/x-gzip .gz .tgz

   #AddHandler cgi-script .cgi
   #AddHandler type-map var

   AddType text/html .shtml
   AddOutputFilter INCLUDES .shtml
</IfModule>

AddDefaultCharset UTF-8

<IfModule mime_magic_module>
   MIMEMagicFile conf/magic
</IfModule>

Alias /error/ "/home/kloxo/httpd/error/"

<IfModule mod_negotiation.c>
   <IfModule mod_include.c>
       <Directory "/home/kloxo/httpd/error/">
           AllowOverride None
           Options IncludesNoExec
           AddOutputFilter Includes html
           AddHandler type-map var
           <IfVersion < 2.4>
               Order allow,deny
               Allow from all
           </IfVersion>
           <IfVersion >= 2.4>
               Require all granted
           </IfVersion>
               LanguagePriority en es de fr
           ForceLanguagePriority Prefer Fallback
       </Directory>

       #ErrorDocument 500 "The server made a boo boo."
       #ErrorDocument 404 /missing.html
       #ErrorDocument 404 "/cgi-bin/missing_handler.pl"
       #ErrorDocument 402 http://www.example.com/subscription_info.html

       ErrorDocument 401 /error/401.html
       ErrorDocument 403 /error/403.html
       ErrorDocument 404 /error/404.html
       ErrorDocument 500 /error/500.html
       ErrorDocument 501 /error/501.html
       ErrorDocument 503 /error/503.html
       ErrorDocument 504 /error/504.html
   </IfModule>
</IfModule>

EnableSendfile on

IncludeOptional conf.d/*.conf

問題出在 nginx - 換行:

proxy_set_header X-Host $var_domain;

proxy_set_header X-Host $host;

解決了問題

首先…停止使用IfModule非可選的位。(不確定什麼是必需的或不需要什麼)它們僅在您有一種在該模組不存在或未載入時恢復的備份方式時才有用。否則,apache 將毫無錯誤地啟動……儘管實際上 90% 的配置不會被載入。

測試並最終修復…的快速方法是刪除所有IfModule語句…然後重新啟動 apache。你幾乎肯定會得到錯誤。閱讀錯誤日誌。看看你得到什麼錯誤……(即無法載入等等)並啟用/安裝/重建使您的站點工作所需的必要模組。

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