ssl 證書申請

https(全稱:Hyper Text Transfer Protocol over Secure Socket Layer),是以安全爲目標的 http 通道,簡單講是 http 的安全版。即 http 下加入 SSL 層,https 的安全基礎是 SSL,所以加密的詳細內容就須要 SSL。在各個 Linux 發行版中,實現 SSL 的通常則是 openssl 套件。

html

一、生成證書請求 CSR 文件node

這裏須要用到 openssl 命令,須要安裝 openssl。git

yum install -y openssl openssl-devel

以 RSA 2048 私鑰舉例,命令以下:github

openssl req -new -nodes -newkey rsa:2048 -sha256 -keyout server.pem -out server.csr

以 ECC 256 私鑰舉例,命令以下:安全

openssl ecparam -out server.pem -name prime256v1 -genkey
openssl req -new -key server.pem -out server.csr

以上命令,在生成 CSR 的時候會有個交互,以下:dom

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]:CN  // 國家代碼
State or Province Name (full name) []:Shanghai  //
Locality Name (eg, city) [Default City]:Shanghai  //
Organization Name (eg, company) [Default Company Ltd]:Teddysun // 組織或公司名(隨便填)
Organizational Unit Name (eg, section) []:  // 部門,可不填
Common Name (eg, your name or your server's hostname) []:teddysun.com // *則是通配符域名,通常證書發行會自帶 www 子域名
Email Address []:admin@teddysun.com  // 郵箱地址(必定要有個域名郵箱,用以驗證域名全部權)

Please enter the following 'extra' attributes
to be sent with your certificate request
A challenge password []:  // 不填
An optional company name []:  // 不填

注意:
這裏的 server.pem 即爲私鑰,須要好好保存,最好你申請下來的證書在配置時,須要用到這個私鑰,一旦私鑰丟失,該證書就廢了,只能從新申請。
通常狀況下,申請 RSA 2048 的證書就足夠了。編輯器

以上步驟所有作完,則會生成兩個文件:
server.pem
server.csrui

將其下載回本地,妥善保管。用任意文本編輯器打開 server.csr,用裏面的內容去申請證書便可。加密

固然,最好是將這 2 個文件更名爲你本身的域名,以方便辨識,好比:spa

example.com.pem
example.com.csr

 

二、申請證書

如今市面上應該已經存在多種免費 SSL(DV)的提供商:
1)letsencrypt (https://github.com/certbot/certbot
2)startssl  (https://www.startssl.com/
3)wosign  (https://buy.wosign.com/free/
4)comodo
5)alphassl
前 3 種都比較容易申請,後 2 種則須要經過一些途徑才能免費獲取的到。付費的則五花八門了,這裏就再也不贅述。申請過程省略。申請成功後,你會獲得一個證書文件(通常後綴名爲 crt)。

注意:
有的證書(好比 comodo 及 alphassl)還須要合併證書鏈,將你獲得的證書以及根證書合併到同一個文件中才能使用。每家的證書鏈都是不同的,若是你是用 letsencrypt 申請的話,默認已是有個完整證書鏈的證書了。
/etc/letsencrypt/live/<domain>/fullchain.pem

Tips:如何合併證書鏈?
用任意文本編輯器打開你的證書文件(好比名稱爲:teddysun_com.crt),在文本的最後面添加根證書(teddysun_com.ca-bundle)裏的所有內容,保存。

 

原文路徑: https://teddysun.com/454.html
相關文章
相關標籤/搜索