1

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      www.${HOST_NAME}
        ServerAlias     ${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      www.${HOST_NAME}
        ServerAlias     ${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 ...


        Header add Set-Cookie "ROUTEID=.%{BALANCER_WORKER_ROUTE}e; path=/" env=BALANCER_ROUTE_CHANGED
        <Proxy "balancer://balancer_domain1">
            BalancerMember http://192.168.2.110:81/         retry=10        route=d1node1
            ProxySet stickysession=ROUTEID
            Require all granted
        </Proxy>

        ProxyPass               /       balancer://balancer_domain1/
        ProxyPassReverse        /       balancer://balancer_domain1/

</VirtualHost>


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

        ServerName      www.${HOST_NAME}
        ServerAlias     ${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      www.${HOST_NAME}
        ServerAlias     ${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 ...


        Header add Set-Cookie "ROUTEID=.%{BALANCER_WORKER_ROUTE}e; path=/" env=BALANCER_ROUTE_CHANGED
        <Proxy "balancer://balancer_domain2">
            BalancerMember http://192.168.2.110:82/         retry=10        route=d2node1
            ProxySet stickysession=ROUTEID
            Require all granted
        </Proxy>

        ProxyPass               /       balancer://balancer_domain2/
        ProxyPassReverse        /       balancer://balancer_domain2/

</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

Med.ZAIRI
  • 11
  • 2
  • While novel, I dont see how thus approach can work, as AFAIK config and keys are read on startup and reload, but not per page - so I dont see how the correct keys or path can be determined at request time. I suspect you need a separate vhost entry for each domain. – davidgo Sep 12 '19 at 03:43
  • Yes, that's what I'm having. a separate vhost for each domain. If you could explain more what you meant by "vhost entry" – Med.ZAIRI Sep 12 '19 at 09:48
  • Actually, I'm dense. I did not fully read the code snippet. I'd try replacing ${HOST_NAME} with the actual content of the variable you defined. I wonder if the parsing of this file is not done sequentially. – davidgo Sep 12 '19 at 09:57

1 Answers1

0

As one year gone, I found the answer from another PROD env, the ProxyPreserHost should not be set to on, cause the host to which the proxy is forwarding the request doesn't respond to the domain called by the end-user.

ProxyPreserveHost       Off
Med.ZAIRI
  • 11
  • 2