開發與維運

Apache 單IP配置多個HTTPS虛擬主機

Apache 文檔中提到,不能在單個 IP上同時有多個按名字識別的虛擬主機("named virtual host"),其實不完全是這樣了。
使用SNI
SNI全稱Server Name Indication(服務器名稱指示),這個問題可以解決apache中的單IP多HTTPS虛擬主機,只有默認第一個站點的SSL生效的問題。但是這些技術需要瀏覽器的版本支持

支持SNI的瀏覽器

  • Mozilla Firefox 2.0 or later
  • Opera 8.0 or later (the TLS 1.1 protocol must be enabled)
  • Internet Explorer 7 (Vista, not XP) or later
  • Google Chrome (Vista, not XP) (NOT Chromium)
  • Safari 3.2.1 Mac OS X 10.5.6

支持SNI的web容器

  • apache版本在2.2.12以上
  • 需要mod_gnutls或者mod_ssl模塊的支持
  • Openssl在0.9.8j後的版本也都支持了SNI的功能

配置Apache

  • 打開Apache/conf/extra/httpd-vhost.conf文件並找到以下參數進行配置。
Listen 443
NameVirtualHost *:443

<VirtualHost *:443>
ServerName www.test1.com
SSLOptions StrictRequire
DocumentRoot /path/to/ssl/enabled/site
SSLProtocol all -SSLv2 -SSLv3
#這裡我們同時禁用了SSLv2、SSLv3不安全的協議
SSLHonorCipherOrder on
SSLCipherSuite HIGH:!RC4:!MD5:!aNULL:!eNULL:!NULL:!DH:!EDH:!EXP:+MEDIUM
SSLCertificateFile conf/server.crt
SSLCertificateKeyFile conf/server.key
SSLCertificateChainFile conf/ca.crt
#默認SSLCertificateChainFile會被註釋,請刪除行首的“#”號註釋符,並將CA證書ca.crt配置到該路徑下
<Directory /path/to/ssl/enabled/site/>
SSLRequireSSL
Order Deny,Allow
Allow from All
</Directory>
</VirtualHost>


<VirtualHost *:443>
ServerName www.test2.com
SSLOptions StrictRequire
DocumentRoot /path/to/other/ssl/enabled/site
SSLProtocol all -SSLv2 -SSLv3
#這裡我們同時禁用了SSLv2、SSLv3不安全的協議
SSLHonorCipherOrder on
SSLCipherSuite HIGH:!RC4:!MD5:!aNULL:!eNULL:!NULL:!DH:!EDH:!EXP:+MEDIUM
SSLCertificateFile conf/server.crt
SSLCertificateKeyFile conf/server.key
SSLCertificateChainFile conf/ca.crt
#默認SSLCertificateChainFile會被註釋,請刪除行首的“#”號註釋符,並將CA證書ca.crt配置到該路徑下
<Directory /path/to/other/ssl/enabled/site/>
SSLRequireSSL
Order Deny,Allow
Allow from All
</Directory>
</VirtualHost>

最後,保存 httpd-vhost.conf 文件並退出,使用https方式訪問網站,測試證書配置是否成功。

Leave a Reply

Your email address will not be published. Required fields are marked *