Apache 2.4 vhosts get redircted (missrouting)

by Med.ZAIRI   Last Updated September 12, 2019 03:00 AM

I have a problem with apache config, like this issue (Apache 2.2.22 - Random Vhost misrouting)

I have multi domains servered by same apache (using vhosts). sometimes I got response from other domain then the one I'm requesting.

Example:

Listen 80
Listen 443

Define HOST_NAME        domain1.com
Define REV_HOST_NAME    com.domain1
#-- HTTP
<VirtualHost *:80>

        ServerName      ${HOST_NAME}
        ServerAlias     www.${HOST_NAME}            *.${HOST_NAME}

        # Redirect any HTTP request to HTTPS
        RewriteEngine On
        RewriteCond %{HTTPS} off
        RewriteRule (.*) https://%{SERVER_NAME}%{REQUEST_URI} [R,L]

        # Logging
        LogLevel warn
        ErrorLog /var/log/httpd/${REV_HOST_NAME}-error.log
        CustomLog /var/log/httpd/${REV_HOST_NAME}-access.log combined

</VirtualHost>

#-- HTTPS
<VirtualHost *:443>

        ServerName      ${HOST_NAME}
        ServerAlias     www.${HOST_NAME}            *.${HOST_NAME}

        #-- Logging
        LogLevel debug
        ErrorLog /var/log/httpd/${REV_HOST_NAME}-error.log
        CustomLog /var/log/httpd/${REV_HOST_NAME}-access.log combined

        ProxyPreserveHost       On
        ProxyRequests           Off
        SSLProxyEngine          On

        SSLEngine               On

        ## some other config here ...

</VirtualHost>


Define HOST_NAME        domain2.com
Define REV_HOST_NAME    com.domain2
#-- HTTP
<VirtualHost *:80>

        ServerName      ${HOST_NAME}
        ServerAlias     www.${HOST_NAME}            *.${HOST_NAME}

        # Redirect any HTTP request to HTTPS
        RewriteEngine On
        RewriteCond %{HTTPS} off
        RewriteRule (.*) https://%{SERVER_NAME}%{REQUEST_URI} [R,L]

        # Logging
        LogLevel warn
        ErrorLog /var/log/httpd/${REV_HOST_NAME}-error.log
        CustomLog /var/log/httpd/${REV_HOST_NAME}-access.log combined

</VirtualHost>

#-- HTTPS
<VirtualHost *:443>

        ServerName      ${HOST_NAME}
        ServerAlias     www.${HOST_NAME}            *.${HOST_NAME}

        #-- Logging
        LogLevel debug
        ErrorLog /var/log/httpd/${REV_HOST_NAME}-error.log
        CustomLog /var/log/httpd/${REV_HOST_NAME}-access.log combined

        ProxyPreserveHost       On
        ProxyRequests           Off
        SSLProxyEngine          On

        SSLEngine               On

        ## some other config here ...

</VirtualHost>

When checking the log /var/log/httpd/com.domain2-error.log, I found this line:

[Thu Sep 12 03:03:52.046630 2019] [ssl:debug] [pid 9009] ssl_engine_kernel.c(1891): [client 102.78.23.167:34001] AH02043: SSL virtual host for servername domain1.com found

Any idea how to fix this issue



Related Questions



htaccess not working at apache 2.4 virtual host

Updated January 13, 2017 01:00 AM

Apache multiple virtual hosts same ServerName

Updated June 01, 2019 23:00 PM

Can't configure two subdomains apache 2.4

Updated April 28, 2015 22:00 PM

Mass virtual hosting with Apache 2.4

Updated May 22, 2017 03:00 AM