0

I've upgraded my Apache 2.2 web server to 2.4 today and then some Wordpress installations started to get infinite loops from non-www to www and from www to non-www :(

Removing .htaccesss didn't helped.

How to solve this ? Example domain config:

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"

and also 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
Marek Zakrzewski
  • 163
  • 1
  • 2
  • 11

2 Answers2

0

First... stop using IfModule on bits that aren't optional. (not sure what is or is not required) They're only useful if you have a fall-back way of recovering if that module doesn't exist or isn't loaded. Otherwise, apache will start without error... despite the fact that 90% of your config won't actually be loaded.

A quick way to test and ultimately fix... is to remove all of the IfModule statements... and then restart apache. You'll almost certainly get errors. Read the error logs. Look at what errors you get... (i.e. can't load blah blah) and enable/install/rebuild the necessary modules that are required to make your site work.

TheCompWiz
  • 7,409
  • 17
  • 23
0

The problem was in nginx - changing line:

proxy_set_header X-Host $var_domain;

to

proxy_set_header X-Host $host;

fixed the problem

Marek Zakrzewski
  • 163
  • 1
  • 2
  • 11