title: X-Forwarded-Host contains wrong virtualhost
body: <p>I have an Apache server acting as a reverse proxy in which two identical virtualhosts are configured: server1 and server2 (see below). There is a CNAME DNS record for server2.mydomain.com which points to server1.mydomain.com. When I hit http://<em>server1</em>.mydomain.com/some/resource, the back-end server sees an X-Forwarded-Host header containing <em>server2</em>.mydomain.com.  Is this a bug or is my configuration incorrect?  </p>
  
  <p>Thanks.</p>
  
  <p>-b</p>
  
  <p>Here's what my virtualhosts look like:</p>
  
  <p>non-SSL (rewrites to SSL)</p>
  
  <pre><code>&lt;VirtualHost *:80&gt;
      ServerAdmin webmaster@localhost
      ServerName server1.mydomain.com
      ServerAlias server1
      ServerSignature off
  
      RewriteEngine On
      RewriteCond %{HTTPS} off
      RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}
  &lt;/VirtualHost&gt;
  &lt;VirtualHost *:80&gt;
      ServerAdmin webmaster@localhost
      ServerName server2.mydomain.com
      ServerAlias server2
      ServerSignature off
  
      RewriteEngine On
      RewriteCond %{HTTPS} off
      RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}
  &lt;/VirtualHost&gt;
  </code></pre>
  
  <p>SSL</p>
  
  <pre><code>&lt;VirtualHost *:443&gt;
      ServerAdmin webmaster@localhost
      ServerName server1.mydomain.com
      ServerSignature off
  
      DocumentRoot ...
  
      &lt;Directory ... /&gt;
  
      Header        edit Location ^http:(.*)$ https:$1
      RequestHeader set X-Forwarded-Proto https
  
      ProxyVia off
      ProxyRequests Off
      ProxyPreserveHost On
  
      SSLProxyEngine On
      ProxyPass / https://back-end.mydomin.com/
      ProxyPassReverse / https://back-end.mydomain.com/
  
      ...
  &lt;VirtualHost&gt;
  &lt;VirtualHost *:443&gt;
      ServerAdmin webmaster@localhost
      ServerName server2.mydomain.com
      ServerSignature off
  
      DocumentRoot ...
  
      &lt;Directory ... /&gt;
  
      Header        edit Location ^http:(.*)$ https:$1
      RequestHeader set X-Forwarded-Proto https
  
      ProxyVia off
      ProxyRequests Off
      ProxyPreserveHost On
  
      SSLProxyEngine On
      ProxyPass / https://back-end.mydomin.com/
      ProxyPassReverse / https://back-end.mydomain.com/
  
      ...
  &lt;VirtualHost&gt;
  </code></pre>