Apache 2.4 vhosts 被重定向(错误路由)

Apache 2.4 vhosts 被重定向(错误路由)

我在 apache 配置方面遇到了问题,例如这个问题(Apache 2.2.22 - 随机 Vhost 错误路由

我有由同一个 apache 服务的多个域(使用 vhosts)。有时我会从我请求的域以外的其他域收到响应。

例子:

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>

检查日志 /var/log/httpd/com.domain2-error.log 时,我发现了这一行:

[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

知道如何修复此问题吗

答案1

一年过去了,我从另一个 PROD 环境中找到了答案,ProxyPreserHost 不应设置为开启,因为代理转发请求的主机不响应最终用户调用的域。

ProxyPreserveHost       Off

相关内容