Apache 2.4.6 虚拟主机 ServerAlias 指令在所有情况下均不匹配别名

Apache 2.4.6 虚拟主机 ServerAlias 指令在所有情况下均不匹配别名

Apache 2.4.6 使用基于名称的虚拟主机托管四个域。对 http 端口 80 的调用被重定向到端口 443。每个虚拟服务器都有两个 ServerAlias 参数,用于指令将调用重定向到http://domain-example.com/或者http://www.domain-example.com/https://domain-example.com/

问题是http://example2.com/由默认虚拟主机重定向(按顺序排列)https://example1.com/更让人费解的是http://example2.com/somepath正确重定向至https://example2.com/somepath

通话和结果摘要:

    http://example1.com/    ==> https://example1.com/
    http://www.example1.com/    ==> https://example1.com/
    https://example1.com/   ==> https://example1.com/
    https://www.example1.com/   ==> https://example1.com/

    http://example2.com/    ==> https://example1.com/ (<== THIS ONE!)
    http://www.example2.com/    ==> https://example2.com/
    https://example2.com/   ==> https://example2.com/
    https://www.example2.com/   ==> https://example2.com/

    http://example3.us/ ==> https://example3.us/
    http://www.example3.us/ ==> https://example3.us/
    https://example3.us/    ==> https://example3.us/
    https://www.example3.us/    ==> https://example3.us/

    http://example4.com/    ==> https://example4.com/
    http://www.example4.com/    ==> https://example4.com/
    https://example4.com/   ==> https://example4.com/
    https://www.example4.com/   ==> https://example4.com/

    http://example2.com/    ==> https://example1.com/
    http://example2.com/somepath    ==> https://example2.com/somepath

virtualhost.conf(防火墙端口被 [value] 替换)

SSLStrictSNIVHostCheck off

<VirtualHost *:80>
  ServerName www.example1.com
  ServerAlias example1.com *.example1.com
  Redirect permanent / https://example1.com/
</VirtualHost>

<VirtualHost *:443>
  ServerName www.example1.com
  ServerAlias example1.com *.example1.com
  ProxyRequests off
  ProxyPreserveHost on
  CustomLog "/path/to/logs/example1ssl.log" "%h %l %u %t \"%r\" %>s %b"
  ErrorLog "/path/to/logs/example1ssl_error.log"
  SSLEngine on
  SSLProxyEngine on
  SSLCertificateFile /path/to/certs/example1.com.crt
  SSLCertificateKeyFile /path/to/private/example1.key
  SSLCertificateChainFile /path/to/certs/ca-bundle-example1.crt
  ProxyPass / http://example1.com:[internal port 1]/
  ProxyPassReverse / http://example1.com:[internal port 1]/
</VirtualHost>

<VirtualHost *:80>
  ServerName www.example2.com
  ServerAlias example2.com *.example2.com
  Redirect permanent / https://example2.com/
</VirtualHost>

<VirtualHost *:443>
  ServerName www.example2.com
  ServerAlias example2.com *.example2.com
  SSLEngine on
  SSLProxyEngine on
  CustomLog "/path/to/logs/example2_ssl.log" "%h %l %u %t \"%r\" %>s %b"
  ErrorLog "/path/to/logs/example2_ssl_error.log"
  SSLCertificateFile /path/to/certs/web-01.example2.com.crt
  SSLCertificateKeyFile /path/to/private/example2.com.key
  SSLCertificateChainFile /path/to/certs/example2.com.crt
  ProxyPreserveHost On
  ProxyRequests off
  ProxyPass / http://example2.com:[internal port 3]/
  ProxyPassReverse / http://example2.com:[internal port 3]/
</VirtualHost>

<VirtualHost *:80>
  ServerName www.example3.us
  ServerAlias example3.us *.example3.us
  Redirect permanent / https://example3.us/
</VirtualHost>

<VirtualHost *:443>
  ServerName www.example3.us
  ServerAlias example3.us *.example3.us
  ProxyRequests off
  ProxyPreserveHost on
  CustomLog "/path/to/logs/example3ssl.log" "%h %l %u %t \"%r\" %>s %b"
  ErrorLog "/path/to/logs/example3ssl_error.log"
  SSLEngine on
  SSLProxyEngine on
  SSLCertificateFile /path/to/certs/example3.us.crt
  SSLCertificateKeyFile /path/to/private/example3.key
  SSLCertificateChainFile /path/to/certs/auth_bundle-example3.crt
  ProxyPass / http://example3.us:[internal port 2]/
  ProxyPassReverse / http://example3.us:[internal port 2]/
</VirtualHost>



<VirtualHost *:80>
  ServerName www.example4.com
  ServerAlias example4.com *.example4.com
  Redirect permanent / https://example4.com/
</VirtualHost>

<VirtualHost *:443>
  ServerName www.example4.com
  ServerAlias example4.com *.example4.com
  ProxyRequests off
  ProxyPreserveHost on
  CustomLog "/path/to/logs/example4ssl.log" "%h %l %u %t \"%r\" %>s %b"
  ErrorLog "/path/to/logs/example4ssl_error.log"
  SSLEngine on

      SSLProxyEngine on
      SSLCertificateFile /path/to/certs/example4.com.crt
      SSLCertificateKeyFile /path/to/private/example4.key
      SSLCertificateChainFile /path/to/certs/ca-bundle-example4.crt
      ProxyPass / http://example4.com:[internal port 4]/
      ProxyPassReverse / http://example4.com:[internal port 4]/
    </VirtualHost>

来自 apachectl -S

VirtualHost configuration:

    *:80                   is a NameVirtualHost
             default server www.example1.com (/etc/httpd/conf.d/virtualhosts.conf:12)
             port 80 namevhost www.example1.com (/etc/httpd/conf.d/virtualhosts.conf:12)
                     alias example1.com
                     wild alias *.example1.com
             port 80 namevhost www.example2.com (/etc/httpd/conf.d/virtualhosts.conf:36)
                     alias example2.com
                     wild alias *.example2.com
             port 80 namevhost www.example3.us (/etc/httpd/conf.d/virtualhosts.conf:84)
                     alias example3.us
                     wild alias *.example3.us
             port 80 namevhost www.example4.com (/etc/httpd/conf.d/virtualhosts.conf:108)
                     alias example4.com
                     wild alias *.example4.com
    *:443                  is a NameVirtualHost
             default server www.example1.com (/etc/httpd/conf.d/virtualhosts.conf:19)
             port 443 namevhost www.example1.com (/etc/httpd/conf.d/virtualhosts.conf:19)
                     alias example1.com
                     wild alias *.example1.com
             port 443 namevhost www.example2.com (/etc/httpd/conf.d/virtualhosts.conf:43)
                     alias example2.com
                     wild alias *.example2.com
             port 443 namevhost www.example3.us (/etc/httpd/conf.d/virtualhosts.conf:90)
                     alias example3.us
                     wild alias *.example3.us
             port 443 namevhost www.example4.com (/etc/httpd/conf.d/virtualhosts.conf:114)
                     alias example4.com
                     wild alias *.example4.com

有什么想法吗?

谢谢

答案1

这似乎是本地(与服务器无关)Chrome 浏览器 DNS 缓存问题。使用 Safari 和 Firefox 时,所有调用都会产生预期的 URL。只有使用 Chrome 时才会出现上述问题。如果我找到原因,我会进一步更新。

答案2

配置虚拟主机时,强烈建议(我强烈建议,如果没有其他人)始终配置一个“默认”虚拟主机,并设置 404 页面或某种重定向到正确的 URL,这样您就不会遇到这种神秘情况。我还会遵循 @TedSpradley 的建议,确保您已清除缓存。我在多个 Web 服务器上都看到过这个问题,浏览器会无限期地缓存页面,从而给您带来意想不到的结果。(虽然不是 DNS 缓存。而是 Web 缓存)

相关内容