最近很多ssl的需求,Google開始對於https的網域進行SEO加分,進一步push整個web加入轉換成https的加密連線環境,這已經是勢不可擋的趨勢了!
而好的ssl憑證以前是要用買的而且有些十分昂貴,各大瀏覽器也不見得會完全支援,常常有花了錢卻得到破掉的盾牌這種鳥事發生,但是在去年開始,各大網路公司一起進行了一個open source program 讓大家都可以得到免費且有效的ssl憑證,而這個專案就是Let’s enscrypt!
利用Let’s enscrypt產生ssl憑證:
把整個專案拉下來
1 |
sudo git clone https://github.com/letsencrypt/letsencrypt /opt/letsencrypt |
獲取ssl憑證
1 |
cd /opt/letsencrypt |
1 |
./letsencrypt-auto certonly -a webroot --webroot-path={$ur-website-host-path} -d {example.com} -d {www.example.com} |
會進入一個畫面,基本上就是填Email跟要Agree後就會產生了。
1 |
sudo ls -l /etc/letsencrypt/live/{example.com} |
這邊就可以看到產生了fullchain.pem和privkey.pem這兩個會需要用到的檔案
Nginx Conf 設定
1 |
sudo vim /etc/nginx/sites-available/{exmaple.com}.conf |
1 2 3 4 5 |
listen 443 ssl; server_name {example.com} {www.example.com}; ssl_certificate /etc/letsencrypt/live/{example.com}/fullchain.pem; ssl_certificate_key /etc/letsencrypt/live/{example.com}/privkey.pem; |
剩下的就照抄之前的設定了,然後重啟nginx即可生效
1 |
sudo service nginx reload |
Auto ReNew 憑證
1 |
./opt/letsencrypt/letsencrypt-auto renew |
這個指令可以renew憑證,所以就放入crontab去
1 |
sudo crontab -e |
把以下這段放進去,就會定時幫我們更新憑證了,這樣就大功告成了!Yes!
1 2 |
30 2 * * 1 /opt/letsencrypt/letsencrypt-auto renew >> /var/log/le-renew.log 35 2 * * 1 /etc/init.d/nginx reload |
參考資料
https://technologyofkevin.com/?p=470
http://www.ithome.com.tw/news/98767
https://blog.serv.idv.tw/2016/02/letsencrypt-ssl-setting/
http://laravel5-book.kejyun.com/hosting/hosting-install-lets-encrypt.html
http://technews.tw/2016/03/10/lets-encrypt-million/
最後補充一個特別的消息,本來想要讓Amazon CDN cloudfront也設定ssl for customer domain,Amazon在今年一月居然佛心來的送ssl憑證 只要使用他們家的cloudfront服務跟EC2,省了我很多事情,一鍵就搞定了!詳情看:AWS 也推出免費的 SSL Certificate 給 ELB 與 CloudFront 用了