我在 FreeBSD 上有一个 Web 服务器 Apache,并且只想将 SSL 绑定到多个域中的一个。现在我的配置是
NameVirtualHost *:80
<VirtualHost *:80>
DocumentRoot /home/web/web/domain01.com
ServerName domain01.com
ServerAlias www.domain01.com
</VirtualHost>
<VirtualHost *:80>
DocumentRoot /home/web/web/ssldomain.com
ServerName ssldomain.com
ServerAlias www.ssldomain.com
</VirtualHost>
<VirtualHost *:443>
DocumentRoot "/home/web/web/ssldomain.com"
ServerName www.ssldomain.com
ServerAlias ssldomain.com
SSLEngine on
SSLCipherSuite ALL:!ADH:!EXPORT56:RC4+RSA:+HIGH:+MEDIUM:+LOW:+SSLv2:+EXP:+eNULL
SSLCertificateFile "/usr/local/etc/apache22/ssl/www.ssldomain.com.crt"
SSLCertificateKeyFile "/usr/local/etc/apache22/ssl/private.key"
SSLCertificateChainFile "/usr/local/etc/apache22/ssl/intermediate.crt"
</VirtualHost>
一切正常,但在浏览器中https://www.domain01.com/显示 ssldomain.com 网站的页面。这很糟糕。
如何调整 Apache 以防止在https://www.domain01.com在浏览器中。
UPD:我尝试为两个域定义 VirtualHosts :80 和 :443。1) 对两个域使用 ssldomain.com 的原始 SSL;2) 对 ssldomain.com 使用原始 SSL,对 domain01.com 使用自签名 SSL。在这两种情况下,浏览器都显示 HTTPS 证书错误,但页面正确。
这两种情况的配置
Include etc/apache22/extra/httpd-ssl.conf
NameVirtualHost *:80
NameVirtualHost *:443
<VirtualHost *:80>
DocumentRoot /home/web/web/domain01.com
ServerName domain01.com
ServerAlias www.domain01.com
</VirtualHost>
<VirtualHost *:443>
DocumentRoot /home/web/web/domain01.com
ServerName domain01.com
ServerAlias www.domain01.com
SSLEngine on
SSLCertificateFile "/usr/local/etc/apache22/ssl/domain01.com/server.cert"
SSLCertificateKeyFile "/usr/local/etc/apache22/ssl/domain01.com/server.key"
# This is for second case (of course 2 lines above are comments)
# SSLCipherSuite ALL:!ADH:!EXPORT56:RC4+RSA:+HIGH:+MEDIUM:+LOW:+SSLv2:+EXP:+eNULL
# SSLCertificateFile "/usr/local/etc/apache22/ssl/www.ssldomain.com.crt"
# SSLCertificateKeyFile "/usr/local/etc/apache22/ssl/private.key"
# SSLCertificateChainFile "/usr/local/etc/apache22/ssl/intermediate.crt"
#Redirect permanent / http://www.domain01.com/
</VirtualHost>
<VirtualHost *:80>
DocumentRoot /home/web/web/ssldomain.com
ServerName ssldomain.com
ServerAlias www.ssldomain.com
</VirtualHost>
<VirtualHost *:443>
DocumentRoot "/home/web/web/ssldomain.com"
ServerName www.ssldomain.com
ServerAlias ssldomain.com
SSLEngine on
SSLCipherSuite ALL:!ADH:!EXPORT56:RC4+RSA:+HIGH:+MEDIUM:+LOW:+SSLv2:+EXP:+eNULL
SSLCertificateFile "/usr/local/etc/apache22/ssl/www.ssldomain.com.crt"
SSLCertificateKeyFile "/usr/local/etc/apache22/ssl/private.key"
SSLCertificateChainFile "/usr/local/etc/apache22/ssl/intermediate.crt"
</VirtualHost>
最诚挚的问候!
答案1
如果 Apache 无法找到具有匹配的 ServerName 或 ServerAlias 的虚拟主机,它将默认为该 IP 的第一个虚拟主机(或匹配的通配符,如本例中的 *)和端口 (443)。因此,您需要在端口 443 上为 www.domain01.com 设置一个单独的站点,就像您已对 www.ssldomain.com:443 所做的那样,这样它就不会退回到您唯一的默认站点。
如果需要,可以将此虚拟主机设置为重定向回 HTTP(请注意,此重定向已完成后SSL 协商仍然需要有效的证书 - 每个 SSL vhost 都需要为其设置一个证书,但如果该证书对该 vhost 也有效,则可以使用相同的证书。
那么,为什么你没有收到证书错误?https://www.domain01.com?我猜要么你是(并且只有当你忽略它时你才会看到 www.ssldomain.com 内容),要么你的证书涵盖两个域(在这种情况下,将其设置为单独的 vhost 并重定向回 http 肯定是可行的方法)。
顺便说一句,与普遍看法相反,你确实不是需要单独的 IP 地址才能在 Apache 实例上设置多个 SSL 主机 - 即使对于不支持 SNI 的旧浏览器也是如此。还有另一种解决方法。有关更多详细信息,请参阅此处:禁用 Apache 上特定虚拟主机的 SNI
答案2
这对我有用,我只改变域的顺序 - 第一个是具有原始 SSL 证书的 ssldomain.com,第二个是具有相同 SSL 证书和重定向的 domain01.com。
Include etc/apache22/extra/httpd-ssl.conf
NameVirtualHost *:80
NameVirtualHost *:443
<VirtualHost *:80>
DocumentRoot /home/web/web/ssldomain.com
ServerName ssldomain.com
ServerAlias www.ssldomain.com
</VirtualHost>
<VirtualHost *:443>
DocumentRoot "/home/web/web/ssldomain.com"
ServerName www.ssldomain.com
ServerAlias ssldomain.com
SSLEngine on
SSLCipherSuite ALL:!ADH:!EXPORT56:RC4+RSA:+HIGH:+MEDIUM:+LOW:+SSLv2:+EXP:+eNULL
SSLCertificateFile "/usr/local/etc/apache22/ssl/www.ssldomain.com.crt"
SSLCertificateKeyFile "/usr/local/etc/apache22/ssl/private.key"
SSLCertificateChainFile "/usr/local/etc/apache22/ssl/intermediate.crt"
</VirtualHost>
<VirtualHost *:80>
DocumentRoot /home/web/web/domain01.com
ServerName domain01.com
ServerAlias www.domain01.com
</VirtualHost>
<VirtualHost *:443>
DocumentRoot /home/web/web/domain01.com
ServerName domain01.com
ServerAlias www.domain01.com
SSLEngine on
SSLCipherSuite ALL:!ADH:!EXPORT56:RC4+RSA:+HIGH:+MEDIUM:+LOW:+SSLv2:+EXP:+eNULL
SSLCertificateFile "/usr/local/etc/apache22/ssl/www.ssldomain.com.crt"
SSLCertificateKeyFile "/usr/local/etc/apache22/ssl/private.key"
SSLCertificateChainFile "/usr/local/etc/apache22/ssl/intermediate.crt"
Redirect permanent / http://www.domain01.com/
</VirtualHost>
特别感谢@BazzaDP。