在两个VirtualHost上使用SSL

时间:2013-07-16 13:45:27

标签: apache ssl subdomain virtualhost vhosts

所以我从GoDaddy那里得到了一个SSL 它适用于我的公共网站mysite.com 我现在希望为administrator.mysite.com提供SSL连接 所以我使用 openssl 创建了一个自签名证书,因为我不介意在锁上用红色标记管理我自己的网站。

httpd-ssl.conf

<VirtualHost *:443>
   ServerName mysite.com:443
   ServerAlias www.mysite.com

   DocumentRoot /opt/lampp/htdocs/MySite/

   ServerAdmin admin@mysite.com

   ErrorLog /opt/lampp/htdocs/MySite/logfiles/ssl_errors.log
   TransferLog /opt/lampp/htdocs/MySite/logfiles/ssl_access.log

   SSLEngine on
   SSLProtocol all -SSLv2
   SSLCipherSuite ALL:!ADH:!EXPORT:!SSLv2:RC4+RSA:+HIGH:+MEDIUM

   SSLCertificateFile /opt/lampp/etc/ssl.crt/mysite.com.crt
   SSLCertificateKeyFile /opt/lampp/etc/ssl.key/server_nopwd.key
   SSLCertificateChainFile /opt/lampp/etc/ssl.crt/gd_bundle.crt

   SetEnvIf User-Agent ".*MSIE.*" nokeepalive ssl-unclean-shutdown
   CustomLog /opt/lampp/htdocs/MySite/logfiles/ssl_request_log "%t %h %{SSL_PROTOCOL}x %{SSL_CIPHER}x \"%r\" %b"
   <FilesMatch "\.(cgi|shtml|phtml|php)$">
    SSLOptions +StdEnvVars
   </FilesMatch>
   <Directory "/opt/lampp/cgi-bin">
     SSLOptions +StdEnvVars
    </Directory>
    BrowserMatch ".*MSIE.*" nokeepalive ssl-unclean-shutdown downgrade-1.0 force-response-1.0

</VirtualHost>                                  

<VirtualHost *:443>
   ServerName administrator.mysite.com:443
   DocumentRoot "/opt/lampp/htdocs/"

   ServerAdmin admin@mysite.com

   ErrorLog /opt/lampp/htdocs/MySite/logfiles/ssl_errors_admin.log
   TransferLog /opt/lampp/htdocs/MySite/logfiles/ssl_access_admin.log

   SSLEngine on
   SSLProtocol all -SSLv2
   SSLCipherSuite ALL:!ADH:!EXPORT:!SSLv2:RC4+RSA:+HIGH:+MEDIUM

   SSLCertificateFile /opt/lampp/etc/ssl.crt/admin.crt
   SSLCertificateKeyFile /opt/lampp/etc/ssl.key/admin.key

   SetEnvIf User-Agent ".*MSIE.*" nokeepalive ssl-unclean-shutdown
   CustomLog /opt/lampp/htdocs/MySite/logfiles/ssl_request_log "%t %h %{SSL_PROTOCOL}x %{SSL_CIPHER}x \"%r\" %b"

<FilesMatch "\.(cgi|shtml|phtml|php)$">
    SSLOptions +StdEnvVars
</FilesMatch>
<Directory "/opt/lampp/cgi-bin">
    SSLOptions +StdEnvVars
</Directory>
BrowserMatch ".*MSIE.*" nokeepalive ssl-unclean-shutdown downgrade-1.0 force-response-1.0

</VirtualHost>      

我收到了这个警告:

[warn] Init: Name-based SSL virtual hosts only work for clients with TLS server name indication support (RFC 4366)

会发生什么情况是管理员主机被重定向到常规主机,这非常烦人

2 个答案:

答案 0 :(得分:4)

我有同样的问题。奇怪的是,有些报道说它对他们有用,就像一个魅力,但对其他人来说不是。我甚至尝试通过 SSLStrictSNIVHostCheck apache指令使用SNI,但没有运气。

ServerAlias 指令与通配符域一起使用时,例如。 * .snakeoil.com 然后 VirtualHost 的顺序配置很重要。如果带有通配符域别名的 VirtualHost

ServerAlias *.snakeoil.com

是第一个首先处理它并避免解析其他vhost的。尝试反转虚拟主机,以便所有这些都是最后一个,例如。

<IfModule mod_ssl.c>

# first vhost
<VirtualHost *:443>
    ServerName vhost1.snakeoil.com
    [...]
</VirtualHost>

# second vhost
<VirtualHost *:443>
    ServerName vhost2.snakeoil.com
    [...]
</VirtualHost>

# Attention!
# All other vhost requests end up here
# Order matters, keep this entry to be the last one
# as a last resort if any of the above don't apply
<VirtualHost *:443>
    ServerName snakeoil.com
    ServerAlias *.snakeoil.com
    [...]
</VirtualHost>

</IfModule>

至少使用 apache 2.2.14

为我工作

答案 1 :(得分:0)

对于较新的浏览器应该可以正常工作,但是可能值得检查一下htaccess规则,因为其中一个规则无意中将admin.mysite.com重定向到mysite.com

您将获得更多警告信息:https://wiki.apache.org/httpd/NameBasedSSLVHostsWithSNI(本质上较旧的浏览器只能查看默认虚拟主机)。