摘要: 免費 HTTPS 證書,了解一下?
HTTPS 已成為業界標准,這篇博客將教你申請Let's Encrypt的免費 HTTPS 證書。
本文的操作是在 Ubuntu 16.04 下進行,使用 nginx 作為 Web 服務器。
1. 安裝 Certbot
Certbot可以用於管理(申請、更新、配置、撤銷和刪除等)Let's Encrypt 證書。這里安裝的是帶 nginx 插件的 certbot:
sudo apt-get update
sudo apt-get install software-properties-common
sudo add-apt-repository -y ppa:certbot/certbot
sudo apt-get update
sudo apt-get install -y python-certbot-nginx
2. 配置 Nginx
vim /etc/nginx/conf.d/fundebug.conf
此時還沒有 HTTPS 證書,因此域名只能使用 80 端口而非 443 端口,網站只能通過 http 協議而非 https 協議訪問:http://www.fundebug.com。
server
{
listen 80;
server_name www.fundebug.com;
}
重啟 nginx:
systemctl restart nginx
3. 配置 DNS
使域名www.fundebug.com指向 nginx 所在服務器的 IP:
如果你想發現代碼中隱藏的 BUG,歡迎免費試用最專業的 BUG 實時監控平台Fundebug!
4. 申請證書
使用 certbot 命令為www.fundebug.com申請 HTTPS 證書。--nginx選項表示 Web 服務器為 nginx,-d選項指定域名,-n選項表示非交互式運行命令。若去除-n選項,則終端會提醒你選擇是否將 http 請求重定向為 https 請求。
certbot --nginx -d www.fundebug.com -n --email help@fundebug.com --agree-tos
證書申請成功之后,會看到以下信息。Let's Encrypt 證書的有效期只有 3 個月,但是Certbot 會通過 Cron 和 systemd timer 自動更新證書,證書的時效性不用擔心。
IMPORTANT NOTES:
- Congratulations! Your certificate and chain have been saved at:
/etc/letsencrypt/live/www.fundebug.com/fullchain.pem
Your key file has been saved at:
/etc/letsencrypt/live/www.fundebug.com/privkey.pem
Your cert will expire on 2018-09-29. To obtain a new or tweaked
version of this certificate in the future, simply run certbot again
with the "certonly" option. To non-interactively renew *all* of
your certificates, run "certbot renew"
- If you like Certbot, please consider supporting our work by:
Donating to ISRG / Let's Encrypt: https://letsencrypt.org/donate
Donating to EFF: https://eff.org/donate-le
HTTPS 證書相關的文件在/etc/letsencrypt/目錄中:
find /etc/letsencrypt/ -name "*www.fundebug.com*"
/etc/letsencrypt/renewal/www.fundebug.com.conf
/etc/letsencrypt/archive/www.fundebug.com
/etc/letsencrypt/live/www.fundebug.com
certbot 會自動修改 nginx 配置文件:
cat /etc/nginx/conf.d/fundebug.conf
nginx 監聽了 443 端口並配置了 HTTPS 證書,這時我們可以通過 HTTPS 協議訪問了!https://www.fundebug.com
server
{
listen 80;
server_name www.fundebug.com;
listen 443 ssl; # managed by Certbot
ssl_certificate /etc/letsencrypt/live/www.fundebug.com/fullchain.pem; # managed by Certbot
ssl_certificate_key /etc/letsencrypt/live/www.fundebug.com/privkey.pem; # managed by Certbot
include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot
}
參考
關於Fundebug
Fundebug專注於JavaScript、微信小程序、微信小游戲、支付寶小程序、React Native、Node.js和Java線上應用實時BUG監控。 自從2016年雙十一正式上線,Fundebug累計處理了10億+錯誤事件,付費客戶有Google、360、金山軟件、百姓網等眾多品牌企業。歡迎大家免費試用!
版權聲明
轉載時請注明作者Fundebug以及本文地址:
https://blog.fundebug.com/2018/07/06/apply-lets-encrypt-certificate/