如果需要设置多个SSL站点,在Apache 2.2以上版本中是开启SSL模块后是直接支持SNI的,添加NameVirtualHost *:443和SSLStrictSNIVHostCheck off两句后,就可以像http虚拟站点一样设置多个https虚拟站点;
多个https虚拟站点可以分别指向多个不同的证书文件,其中第一个默认https站点是在后续https站点配置找不到的时候自动使用的默认配置;
生产环境中apache版本:
[root@localhost ~]# httpd -v
Server version: Apache/2.2.15 (Unix)
Server built: Jan 12 2017 17:09:39
ssl.conf配置文件中配置多https域名对应单个证书和多个不同的https域名对应多个不同的证书,其中第一个默认https站点是在后续https站点配置找不到的时候自动使用的默认配置;
[root@localhost ~]# cat /etc/httpd/conf.d/ssl.conf|egrep -v "^#|^$"
LoadModule ssl_module modules/mod_ssl.so
Listen 443
NameVirtualHost :443
SSLStrictSNIVHostCheck off
SSLPassPhraseDialog builtin
SSLSessionCache shmcb:/var/cache/mod_ssl/scache(512000)
SSLSessionCacheTimeout 300
SSLMutex default
SSLRandomSeed startup file:/dev/urandom 256
SSLRandomSeed connect builtin
SSLCryptoDevice builtin
<VirtualHost default:443>
DocumentRoot "/data/code"
ServerName en.lsj.com:443
ServerName uo.kvc.com:443
ServerName n.purdf.com:443
ServerName a.wifth.com:443
ErrorLog logs/ssl_error_log
LogLevel warn
SSLEngine on
SSLProtocol all -SSLv2 -SSLv3
SSLCipherSuite AESGCM:ALL:!DH:!EXPORT:!RC4:+HIGH:!MEDIUM:!LOW:!aNULL:!eNULL;
SSLCertificateFile /etc/pki/tls/certs/ca.b23c.com.crt
SSLCertificateKeyFile /etc/pki/tls/private/ca.b23c.com.key
SSLCertificateChainFile /etc/pki/tls/certs/root_bundle.crt
<Files ~ ".(cgi|shtml|phtml|php3?)$">
SSLOptions +StdEnvVars
</Files>
<Directory "/var/www/cgi-bin">
SSLOptions +StdEnvVars
</Directory>
SetEnvIf User-Agent ".MSIE." \
nokeepalive ssl-unclean-shutdown \
downgrade-1.0 force-response-1.0
"%t %h %{SSL_PROTOCOL}x %{SSL_CIPHER}x \"%r\" %b"
</VirtualHost>
<VirtualHost :443>
ServerName e.diogv.com
DocumentRoot "/data/code"
LogLevel warn
ErrorLog logs/ssl_error_log
SSLEngine on
SSLProtocol all -SSLv2 -SSLv3
SSLCipherSuite AESGCM:ALL:!DH:!EXPORT:!RC4:+HIGH:!MEDIUM:!LOW:!aNULL:!eNULL;
#注意以下证书文件路径
SSLCertificateFile /etc/pki/tls/certs/e.diogv.com.crt
SSLCertificateKeyFile /etc/pki/tls/private/e.diogv.com.key
SSLCertificateChainFile /etc/pki/tls/certs/e.diogv.com_bundle.crt
<Files ~ ".(cgi|shtml|phtml|php3?)$">
SSLOptions +StdEnvVars
</Files>
<Directory "/var/www/cgi-bin">
SSLOptions +StdEnvVars
</Directory>
SetEnvIf User-Agent ".MSIE." \
nokeepalive ssl-unclean-shutdown \
downgrade-1.0 force-response-1.0
"%t %h %{SSL_PROTOCOL}x %{SSL_CIPHER}x \"%r\" %b"
</VirtualHost>
##########################################
<VirtualHost :443>
ServerName e.fst01w.com
DocumentRoot "/data/code"
LogLevel warn
ErrorLog logs/ssl_error_log
SSLEngine on
SSLProtocol all -SSLv2 -SSLv3
SSLCipherSuite AESGCM:ALL:!DH:!EXPORT:!RC4:+HIGH:!MEDIUM:!LOW:!aNULL:!eNULL;
#注意以下证书文件路径
SSLCertificateFile /etc/pki/tls/certs/e.fst01w.com.crt
SSLCertificateKeyFile /etc/pki/tls/private/e.fst01w.com.key
SSLCertificateChainFile /etc/pki/tls/certs/e.fst01w.com_bundle.crt
<Files ~ ".(cgi|shtml|phtml|php3?)$">
SSLOptions +StdEnvVars
</Files>
<Directory "/var/www/cgi-bin">
SSLOptions +StdEnvVars
</Directory>
SetEnvIf User-Agent ".MSIE." \
nokeepalive ssl-unclean-shutdown \
downgrade-1.0 force-response-1.0
"%t %h %{SSL_PROTOCOL}x %{SSL_CIPHER}x \"%r\" %b"
</VirtualHost>
############################################
<VirtualHost :443>
ServerName e.i12erq.com
DocumentRoot "/data/code"
LogLevel warn
ErrorLog logs/ssl_error_log
SSLEngine on
SSLProtocol all -SSLv2 -SSLv3
SSLCipherSuite AESGCM:ALL:!DH:!EXPORT:!RC4:+HIGH:!MEDIUM:!LOW:!aNULL:!eNULL;
#注意以下证书文件路径
SSLCertificateFile /etc/pki/tls/certs/e.i12erq.com.crt
SSLCertificateKeyFile /etc/pki/tls/private/e.i12erq.com.key
SSLCertificateChainFile /etc/pki/tls/certs/e.i12erq.com_bundle.crt
<Files ~ ".(cgi|shtml|phtml|php3?)$">
SSLOptions +StdEnvVars
</Files>
<Directory "/var/www/cgi-bin">
SSLOptions +StdEnvVars
</Directory>
SetEnvIf User-Agent ".MSIE." \
nokeepalive ssl-unclean-shutdown \
downgrade-1.0 force-response-1.0
"%t %h %{SSL_PROTOCOL}x %{SSL_CIPHER}x \"%r\" %b"
</VirtualHost>
##########################################
<VirtualHost :443>
ServerName e.j34ja.com
DocumentRoot "/data/code"
LogLevel warn
ErrorLog logs/ssl_error_log
SSLEngine on
SSLProtocol all -SSLv2 -SSLv3
SSLCipherSuite AESGCM:ALL:!DH:!EXPORT:!RC4:+HIGH:!MEDIUM:!LOW:!aNULL:!eNULL;
#注意以下证书文件路径
SSLCertificateFile /etc/pki/tls/certs/e.j34ja.com.crt
SSLCertificateKeyFile /etc/pki/tls/private/e.j34ja.com.key
SSLCertificateChainFile /etc/pki/tls/certs/e.j34ja.com_bundle.crt
<Files ~ ".(cgi|shtml|phtml|php3?)$">
SSLOptions +StdEnvVars
</Files>
<Directory "/var/www/cgi-bin">
SSLOptions +StdEnvVars
</Directory>
SetEnvIf User-Agent ".MSIE.*" \
nokeepalive ssl-unclean-shutdown \
downgrade-1.0 force-response-1.0
"%t %h %{SSL_PROTOCOL}x %{SSL_CIPHER}x \"%r\" %b"
</VirtualHost>
###################################
<VirtualHost :443>
ServerName e.mi56v.com
DocumentRoot "/data/code"
LogLevel warn
ErrorLog logs/ssl_error_log
SSLEngine on
SSLProtocol all -SSLv2 -SSLv3
SSLCipherSuite AESGCM:ALL:!DH:!EXPORT:!RC4:+HIGH:!MEDIUM:!LOW:!aNULL:!eNULL;
#注意以下证书文件路径
SSLCertificateFile /etc/pki/tls/certs/e.mi56v.com.crt
SSLCertificateKeyFile /etc/pki/tls/private/e.mi56v.com.key
SSLCertificateChainFile /etc/pki/tls/certs/e.mi56v.com_bundle.crt
<Files ~ ".(cgi|shtml|phtml|php3?)$">
SSLOptions +StdEnvVars
</Files>
<Directory "/var/www/cgi-bin">
SSLOptions +StdEnvVars
</Directory>
SetEnvIf User-Agent ".MSIE.*" \
nokeepalive ssl-unclean-shutdown \
downgrade-1.0 force-response-1.0
"%t %h %{SSL_PROTOCOL}x %{SSL_CIPHER}x \"%r\" %b"
</VirtualHost>
本文转自 wjw555 51CTO博客,原文链接:http://blog.51cto.com/wujianwei/2049132