我有一个 Apache 服务器充当反向代理,其中配置了两个相同的虚拟主机:server1 和 server2(见下文)。server2.mydomain.com 的 CNAME DNS 记录指向 server1.mydomain.com。当我点击 http:// server1 .mydomain.com/some/resource 时,后端服务器会看到一个包含server2 .mydomain.com 的 X-Forwarded-Host 标头。这是一个错误还是我的配置不正确?
谢谢。
-b
这是我的虚拟主机的样子:
非 SSL(重写为 SSL)
<VirtualHost *:80>
ServerAdmin webmaster@localhost
ServerName server1.mydomain.com
ServerAlias server1
ServerSignature off
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}
</VirtualHost>
<VirtualHost *:80>
ServerAdmin webmaster@localhost
ServerName server2.mydomain.com
ServerAlias server2
ServerSignature off
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}
</VirtualHost>
SSL
<VirtualHost *:443>
ServerAdmin webmaster@localhost
ServerName server1.mydomain.com
ServerSignature off
DocumentRoot ...
<Directory ... />
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/
...
<VirtualHost>
<VirtualHost *:443>
ServerAdmin webmaster@localhost
ServerName server2.mydomain.com
ServerSignature off
DocumentRoot ...
<Directory ... />
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/
...
<VirtualHost>