原文:https://keelii.github.io/2016/06/12/free-https-cert-lets-encrypt-apply-install/nginx
以前要申請免費的 https 證書操做步驟至關麻煩,今天看到有人在討論,就搜索了一下。發現如今申請步驟簡單多了。git
git clone https://github.com/certbot/certbot cd certbot ./certbot-auto --help
解壓打開執行就會有相關提示github
./certbot-auto certonly --webroot --agree-tos -v -t --email 郵箱地址 -w 網站根目錄 -d 網站域名 ./certbot-auto certonly --webroot --agree-tos -v -t --email keeliizhou@gmail.com -w /path/to/your/web/root -d note.crazy4code.com
注意 這裏 默認會自動生成 /__網站根目錄__/.well-known/acme-challenge,而後 shell 腳本會對應的訪問 __網站域名__/.well-known/acme-challengeweb
若是返回正常就確認了你對這個網站的全部權,就能順利生成shell
若是上面的步驟正常 shell 腳本會展現以下信息:bash
- Congratulations! Your certificate and chain have been saved at /etc/letsencrypt/live/網站域名/fullchain.pem ...
使用 openssl 工具生成 dhparamsapp
openssl dhparam -out /etc/ssl/certs/dhparams.pem 2048
打開 nginx server 配置文件加入以下設置:dom
listen 443 ssl on; ssl_certificate /etc/letsencrypt/live/網站域名/fullchain.pem; ssl_certificate_key /etc/letsencrypt/live/網站域名/privkey.pem; ssl_dhparam /etc/ssl/certs/dhparams.pem; ssl_protocols SSLv3 TLSv1 TLSv1.1 TLSv1.2; ssl_ciphers HIGH:!aNULL:!MD5;
而後重啓 nginx 服務就能夠了工具
https 默認是監聽 443 端口的,沒開啓 https 訪問的話通常默認是 80 端口。若是你肯定網站 80 端口上的站點都支持 https 的話加入下面的配件能夠自動重定向到 https網站
server { listen 80; server_name your.domain.com; return 301 https://$server_name$request_uri; }