Cloudflare Proxy Causing Apache to Improperly Distinguish between Domains

When the Cloudflare proxy is enabled, Apache, which has two websites deployed, cannot correctly distinguish the requested domain. For example, domain a.com corresponds to website A (a.html), while b.com corresponds to website B (b.html). When the Cloudflare proxy is turned on, accessing b.com actually displays website A. When the Cloudflare proxy is disabled, accessing b.com correctly displays website B. However, accessing a.com always displays website A correctly.

Here is my Apache configuration with the domains replaced with a.com and b.com:

<VirtualHost *:80>
    ServerName a.com
    ServerAlias www.a.com 
    DocumentRoot /var/www/html

    <Directory /var/www/html>
        Options FollowSymLinks
        AllowOverride All
        Require all granted
        DirectoryIndex index.html
    </Directory>

    ErrorLog ${APACHE_LOG_DIR}/a.com_error.log
    CustomLog ${APACHE_LOG_DIR}/a.com_access.log combined
RewriteEngine on
RewriteCond %{SERVER_NAME} =www.a.com [OR]
RewriteCond %{SERVER_NAME} =a.com
RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent]
</VirtualHost>

<VirtualHost *:80>
    ServerName b.com
    ServerAlias www.b.com
    DocumentRoot /var/www/website2

    <Directory /var/www/website2>
        Options FollowSymLinks
        AllowOverride All
        Require all granted
        DirectoryIndex index.html
    </Directory>

    ErrorLog ${APACHE_LOG_DIR}/b.com_error.log
    CustomLog ${APACHE_LOG_DIR}/b.com_access.log combined
RewriteEngine off
RewriteCond %{SERVER_NAME} =www.b.com [OR]
RewriteCond %{SERVER_NAME} =b.com
RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent]
</VirtualHost>

What could be causing this issue and how can I resolve it?

This topic was automatically closed 15 days after the last reply. New replies are no longer allowed.