Nginx支持多域名ssl證書【轉】

導讀:
昨天凌晨將公司旗下的另外一個域名也升級成通過ssl證書登錄的形式,那裏料到過程竟然非常曲折,原因是nginx如果編譯的時候使用openssl如果沒有添加enable-tl***t參數的話,就只支持一個ssl證書,因此要讓nginx支持多域名證書就必須要重新編譯openssl和nginx。


詳細過程:
升級更改完nginx配置文件以後,使用/usr/local/nginx/sbin/nginx -t測試配置文件沒有問題,就採用/usr/local/nginx/sbin/nginx -s reload重新加載配置文件,輸入新域名的https訪問竟然出現錯誤證書的提示,左鍵點擊證書錯誤,選擇查看證書,發現用的是另外一個域名的證書。反覆檢查後錯誤依舊。心中轉念一想:是不是nginx只支持一個證書?帶着這個問題,在baidu和google上搜索了一下,還真的是這個問題,要讓nginx支持多證書,nginx必須支持TLS SNI,使用命令/usr/local/nginx/sbin/nginx -V查看,服務器的查看結果如下:

nginx version: nginx/1.0.12

TLS SNI support disabled

configure arguments: –prefix=/usr/local/nginx –with-http_ssl_module –with-http_gzip_static_module –with-http_stub_status_module

很明顯,不支持TLS SNI,需要重新編譯openssl和nginx。

接下來我們詳細敘述一下能讓nginx支持多域名證書的過程,主要分爲如下兩個大步驟:編譯安裝openssl和編譯安裝nginx(nginx平滑升級,不影響業務)。

一、編譯安裝openssl

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

#編譯的時候需要加上enable-tl***t參數

./config enable-tl***t

make

make install

二、編譯安裝nginx(nginx平滑升級)

tar xzvf nginx-1.0.12.tar.gz

cd nginx-1.0.12

#備份原來的nginx配置

mv /usr/local/nginx /usr/local/nginx_old

#安裝nginx

./configure –prefix=/usr/local/nginx –with-http_ssl_module –with-http_gzip_static_module –with-http_stub_status_module –with-openssl=../openssl-0.9.8l/

make;make install

cd /usr/local/nginx

#備份新安裝的配置目錄

mv conf conf_bak

mv logs logs_bak

#拷貝原來的配置文件目錄

cp -ar /usr/local/nginx_old/conf .

cp -ar /usr/local/nginx_old/logs .

#測試配置文件

/usr/local/nginx/sbin/nginx -t

#查找nginx主進程

ps -ef | grep “nginx: master process” | grep -v “grep” | awk -F ‘ ‘ ‘{print $2}’

#執行切換操作

kill -USR2 912

kill -WINCH 912

kill -QUIT 912

安裝完成使用/usr/local/nginx/sbin/nginx -V查看一下是否支持TLS SNI,檢測如下:

nginx version: nginx/1.0.12

TLS SNI support enabled

configure arguments: –prefix=/usr/local/nginx –with-http_ssl_module –with-http_gzip_static_module –with-http_stub_status_module –with-openssl=../openssl-0.9.8l/

Ok,顯示已經支持了TLS SNI,在輸入https訪問,終於能顯示正確的證書了! 注意目前如果使用xp上的IE去訪問的話還是會提示證書有問題,因爲xp上任何版本的IE都不支持TLS SNI。

轉自:http://blog.chinaunix.net/uid-20639775-id-3213595.html

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章