傳統的每一個SSL證書籤發,每一個證書都須要獨立ip,假如你編譯openssl和nginx時候開啓TLS SNI (Server Name Identification) 支持,這樣你能夠安裝多個SSL,綁定不一樣的域名,能夠共享同一個ip。php
近期因爲遇到申請通配符版證書時,好比*.bb.com這樣的二級域名時,主域名爲二級域名時,主域名和其子通配符下的域名能夠用同一張證書,可是像*.aa.bb.com這樣的證書不包含其三級主域名,只有二級的域名支持。此時便會遇到這種一個IP綁定多個證書的狀況。html
一、編譯openssl支持TLS SNI 注意:最新版的openssl可能不支持enable-tlsextnginx
cd /usr/src/
wget http://www.openssl.org/source/openssl-0.9.8l.tar.gz
tar zxvf ./openssl-0.9.8l.tar.gz
cd ./openssl-0.9.8l
./config enable-tlsext
make
make installweb
二、編譯nginx支持TLS SNI,首先驗證本地的nginx是TLS SNI是否支持:ui
/usr/local/nginx/sbin/nginx -V
nginx: nginx version: nginx/1.1.0
nginx: TLS SNI support disable
cd /usr/src/
wget http://nginx.org/download/nginx-0.7.67.tar.gz
tar zxvf nginx-0.7.67.tar.gz
cd nginx-0.7.67spa
./configure \
--prefix=/usr \
--sbin-path=/usr/sbin/nginx \
--conf-path=/etc/nginx/nginx.conf \
--error-log-path=/var/log/nginx/error.log \
--http-log-path=/var/log/nginx/access.log \
--pid-path=/var/run/nginx.pid \
--lock-path=/var/lock/nginx.lock \
--user=nobody\
--group=nobody\
--with-http_stub_status_module\
--with-http_ssl_module \
--with-http_flv_module \
--with-http_gzip_static_module \
--http-client-body-temp-path=/var/tmp/nginx/client_temp/ \
--http-proxy-temp-path=/var/tmp/nginx/proxy_temp/ \
--http-fastcgi-temp-path=/var/tmp/nginx/fcgi_temp/ \
--with-openssl=../openssl-0.9.8l/
makecode
mv /usr/local/nginx/sbin/nginx /usr/local/nginx/sbin/nginx.oldserver
cp objs/nginx /usr/local/nginx/sbin/nginxhtm
/usr/local/nginx/sbin/nginx -tblog
/usr/local/nginx/sbin/nginx -V
若是成功的話此時會看到: TLS SNI support enabled
這樣就能夠在 同一個IP上配置多個HTTPS主機了。
實例以下:
server { listen 443; server_name *.www.aabb.com; index index.html index.htm index.php; root /data/wwwroot/www.aabb.com/webroot; ssl on; ssl_certificate "/usr/local/nginx/conf/ssl/_.www.aabb.com.public.cer"; ssl_certificate_key "/usr/local/nginx/conf/ssl/_.www.aabb.com.private.key"; ...... } server { listen 443; server_name www.aabb.com; index index.html index.htm index.php; root /data/wwwroot/www.aabb.com/webroot; ssl on; ssl_certificate "/usr/local/nginx/conf/ssl/www.aabb.com.public.cer"; ssl_certificate_key "/usr/local/nginx/conf/ssl/www.aabb.com.private.key"; ...... }
這樣訪問每一個虛擬主機都正常。
------------------------------------------------------------------------------------
配置Haproxy的配置文件:
按照以上配置就能夠實現多證書的HTTPS,依次訪問上面的訪問會發現,相關的證書與之配對。