使用多站点的 apache2 的 SSL

使用多站点的 apache2 的 SSL

我正在测试 startssl 证书,以便在 apache2 内部的不同站点上使用。

我在 apache2 中使用了虚拟主机(全部都是标准配置)的简单配置。测试的两个域在 /etc/apache/sites-avaliable 中定义,例如:

测试1.conf

<VirtualHost *:80>
    DocumentRoot /var/www/test1/
    ServerName www.test1.com

        ErrorLog ${APACHE_LOG_DIR}/error_test1.log
        CustomLog ${APACHE_LOG_DIR}/access_test1.log combined
     RewriteEngine on
        ReWriteCond %{SERVER_PORT} !^443$
        RewriteRule ^/(.*) https://%{HTTP_HOST}/$1 [NC,R,L]
</VirtualHost>
<VirtualHost *:443>
        ServerAdmin [email protected]
        DocumentRoot /var/www/test1/

        SSLEngine on
        SSLProtocol all -SSLv2
        SSLCipherSuite ALL:!ADH:!EXPORT:!SSLv2:RC4+RSA:+HIGH:+MEDIUM
        SSLCertificateFile /etc/ssl/certs/ssl.crt
        SSLCertificateKeyFile /etc/ssl/private/ssl_dec.key
        SSLCertificateChainFile /etc/ssl/certs/sub.class1.server.ca.pem
</VirtualHost>

测试2.conf

<VirtualHost *:80>

        DocumentRoot /var/www/test2/
        ServerName test2.com

        CustomLog ${APACHE_LOG_DIR}/wp_test2.log combined
        ErrorLog ${APACHE_LOG_DIR}/wp_test2_error.log
    RewriteEngine off
        ReWriteCond %{SERVER_PORT} !^443$
        RewriteRule ^/(.*) https://%{HTTP_HOST}/$1 [NC,R,L]

</VirtualHost>
<VirtualHost *:443>
        ServerAdmin [email protected]
        DocumentRoot /var/www/test2/
        SSLEngine on
        SSLProtocol all -SSLv2
        SSLCipherSuite ALL:!ADH:!EXPORT:!SSLv2:RC4+RSA:+HIGH:+MEDIUM
        SSLCertificateFile /etc/ssl/certs/think.crt
        SSLCertificateKeyFile /etc/ssl/private/think_dec.key
        SSLCertificateChainFile /etc/ssl/certs/sub.class1.server.ca.pem
</VirtualHost>

我发现第二个域不接受 SSL 证书。

出现 error_bad_cert_doamin 是因为 test2 正在使用 test1 证书。如果我只使用一个域名,则一切正常。问题可能出在哪里?

答案1

您还必须在 SSL 配置中设置服务器名称:

<VirtualHost *:443>
        ServerName test1.com
        ServerAdmin [email protected]
        DocumentRoot /var/www/test1/
        SSLEngine on
        SSLProtocol all -SSLv2
        SSLCipherSuite ALL:!ADH:!EXPORT:!SSLv2:RC4+RSA:+HIGH:+MEDIUM
        SSLCertificateFile /etc/ssl/certs/ssl.crt
        SSLCertificateKeyFile /etc/ssl/private/ssl_dec.key
        SSLCertificateChainFile /etc/ssl/certs/sub.class1.server.ca.pem
</VirtualHost>

<VirtualHost *:443>
        ServerName test2.com
        ServerAdmin [email protected]
        DocumentRoot /var/www/test2/
        SSLEngine on
        SSLProtocol all -SSLv2
        SSLCipherSuite ALL:!ADH:!EXPORT:!SSLv2:RC4+RSA:+HIGH:+MEDIUM
        SSLCertificateFile /etc/ssl/certs/think.crt
        SSLCertificateKeyFile /etc/ssl/private/think_dec.key
        SSLCertificateChainFile /etc/ssl/certs/sub.class1.server.ca.pem
</VirtualHost>

相关内容