在付費SSL憑證選項中,rapidSSL可以說是最便宜的選項之一,單一網域憑證的費用約3年3300元,通用網域憑證(WildCard)的費用約3年13500元,可以讓該網域下的所有網域名稱皆能套用這個通用網域憑證,是中小企業的最佳選擇,本次要示範的便是這種WildCard系列的憑證。一般直接在網路上找一個SSL憑證代理商協助即可,但還是有一些工作是得靠自己來的,本文將從建立私鑰、建立憑證簽發請求文件、取得簽發許可的SSL憑證、合併中繼CA憑證與WEB伺服器端的設定依序說明。
建立私鑰,安全度來說建議是2048位元或以上的rsa金鑰規格
[root@centos6 ~]# openssl genrsa -out private.key 2048
利用自建私鑰建立憑證簽發請求文件,通用網域憑證的部分請在common name加上星號,單一網域憑證則直接在common name輸入FQDN即可,最終會產出一份csr請求文件。[root@centos6 ~]# openssl req -new -key private.key -out 123_com_tw.csr
You are about to be asked to enter information that will be incorporated
into your certificate request.
What you are about to enter is what is called a Distinguished Name or a DN.
There are quite a few fields but you can leave some blank
For some fields there will be a default value,
If you enter '.', the field will be left blank.
-----
Country Name (2 letter code) [XX]:TW
State or Province Name (full name) []:Taiwan
Locality Name (eg, city) [Default City]:Taipei
Organization Name (eg, company) [Default Company Ltd]:Tomy168
Organizational Unit Name (eg, section) []:MIS
Common Name (eg, your name or your server's hostname) []:*.123.com.tw
Email Address []: Enter即可
Please enter the following 'extra' attributes
to be sent with your certificate request
A challenge password []:Enter即可
An optional company name []:Enter即可
[root@centos6 ~]# ls
123_tom_tw.csr private.key
將產出的csr檔案交付給SSL憑證機構或由你的SSL憑證代理商幫忙交付,並提交收取SSL憑證的Email,這裡需要注意的是你需要提交的是該網域管理者的email以證明你是這個網域的持有者,(例如:admin、administrator、postmaster、webmaster、hostmaster@123.com.tw等)。當天你所提交的Email就會收到一封信,大意是請你依照信中連結去核准這個憑證的申請,接著約莫幾天後就可以收到從orderprocessing@rapidssl.com寄給你的SSL憑證囉!憑證的內容大致如下,將他存成一個XXX.crt即可。
-----BEGIN CERTIFICATE-----
MIIDSDCCAjACCQCqI0Sh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Rd6hhMUz
WekHcgOntKnWoZ9RDV67cg3y2/XOk0DZnuIw+Q==
-----END CERTIFICATE-----
在nginx設定的部分,需要有一些參數的設置以提升網站的整體安全性,而一張完整的憑證除了SSL憑證機構核發給你的crt原始檔以外,還須事先合併中繼憑證(intermediate CA)才能使用,中繼憑證可向你的SSL憑證代理商索取或參照orderprocessing@rapidssl.com寄給你的SSL憑證信件中會有相關索取連結。[root@centos6 ~]# cat XXX.crt intermediate.crt > 123_com_tw.crt
另外為了提升https在建立連接時的Forward Secrecy,還需要建立一個高強度的Diffie-Hellman (DH) key exchange parameters,建議是4096位元。[root@centos6 ~]# openssl dhparam -out dhparam.pem 4096
萬事俱備,我們開始設定nginx.conf。[root@centos6 ~]# nano /etc/nginx/conf/nginx.conf
#找到server字段,新增以下包含ssl開頭的內容。
server
{
listen 443;
server_name www.123.com.tw;
error_page 405 =200 $uri;
root /var/www/html/123/;
index index.php index.html index.htm;
ssl on;
ssl_certificate /etc/ssl/123_com_tw/123_com_tw.crt;
ssl_certificate_key /etc/ssl/123_com_tw/private.key;
ssl_dhparam /etc/ssl/123_com_tw/dhparam.pem;
ssl_verify_depth 1;
ssl_session_timeout 5m;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_prefer_server_ciphers on;
ssl_session_cache shared:SSL:10m;
ssl_ciphers "EECDH+AESGCM:EDH+AESGCM:ECDHE-RSA-AES128-GCM-SHA256:AES256+EECDH:DHE-RSA-AES128-GCM-SHA256:AES256+EDH:ECDHE-RSA-AES256-GCM-SHA384:DHE-RSA-ES256-GCM-SHA384:ECDHE-RSA-AES256-SHA384:ECDHE-RSA-AES128-SHA256:ECDHE-RSA-AES256-SHA:ECDHE-RSA-AES128-SHA:DHE-RSA-AES256-SHA256:DHE-RSA-AES128-SHA256:DHE-RSA-AES256-SHA:DHE-RSA-AES128-SHA:ECDHE-RSA-DES-CBC3-SHA:EDH-RSA-DES-CBC3-SHA:AES256-GCM-SHA384:AES128-GCM-SHA256:AES256-SHA256:AES128-SHA256:AES256-SHA:AES128-SHA:DES-CBC3-SHA:HIGH:!aNULL:!eNULL:!EXPORT:!DES:!MD5:!PSK:!RC4";
...
...
...
}
ssl_protocols參數注意不要加入不安全的sslv2和sslv3。
ssl_prefer_server_ciphers參數啟用是告知客戶端優先採用伺服器所提供的加密通訊方式。
ssl_verify_depth參數預設值就是1,這要求了伺服器的憑證必須是由最上層機構簽發、不允許只由中繼CA簽發的狀況發生。
ssl_ciphers參數後面接的是伺服器所支援與不支援的加密演算法(像是有驚嘆號的就是被標註不支援的演算法,可能是該演算法已經不合時宜或安全性過低)。
最後重啟或平滑重啟你的nginx服務即生效。
[root@centos6 ~]# service nginx reload
完成後可以透過[ssllab]來檢查網站的安全可靠程度。
0 Comments:
張貼留言