使用Certbot 生成 https 证书
1.下載certbot項目
# git clone https://github.com/certbot/certbot.git
# cd certbot/
# chmod a+x ./certbot-auto
?
2.生成一個或多個單域名證書,事先要確保80、443端口可以通,并且沒有被占用,最后域名有解析并且解析到當前服務器
# ./certbot-auto certonly --standalone -m 393008735@qq.com -d yzq.ngrok.yuzq.org -d que.ngrok.org
certonly?? ?表示僅生成證書, 不自動安裝
-d ?參數為域名, 可以存在多個參數, 表示多個域名
-m? 參數為管理者郵箱
?
【1】如果報錯"...We were not be able to guess the right solution from your pip
output",這可能是因為系統鏡像沒同步完整pypi倉庫(比如阿里云),切換成清華大學站或者使用官網倉庫(將 /root/.pip/pip.conf改個名字),重新執行上面的命令
?
【2】如果報錯"OSError: Command /opt/eff.org/certbot/venv/bin/python2.7 - setuptools pip wheel failed with error code 1",執行pip?install?--upgrade?virtualenv?,再執行上面命令
?
證書生成成功,會將證書地址顯示出來(如 /etc/letsencrypt/live/yzq.ngrok.yuzq.org/fullchain.pem)
IMPORTANT NOTES:
- Congratulations! Your certificate and chain have been saved at:
/etc/letsencrypt/live/yzq.ngrok.yuzq.org/fullchain.pem
Your key file has been saved at:
/etc/letsencrypt/live/yzq.ngrok.yuzq.org/privkey.pem
Your cert will expire on 2019-01-23. To obtain a new or tweaked
version of this certificate in the future, simply run certbot-auto
again. To non-interactively renew *all* of your certificates, run
"certbot-auto 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
?
?
3.生成泛域名證書
(1)交互式方式創建泛域名證書
# ./certbot-auto certonly --manual --server https://acme-v02.api.letsencrypt.org/directory -m 393008735@qq.com -d *.ngrok.yuzq.org
certonly?表示僅生成證書, 不自動安裝
--manual?表示以交互式方式創建證書, 或使用?--standalone?模式, certbot 會自動創建一個WebServer進行校驗
--server? 參數為當前使用的ACME協議版本, 這里需要特別注意的是, 只有V2版本才支持泛域名, certbot 工具默認的協議是V1. 因此如需創建泛域名證書, 則必須制定此參數, 且該參數值固定
-d? 參數為域名, 可以存在多個參數, 表示多個域名
-m? 參數為管理者郵箱
?
接下來有幾步要確認
1.Are you OK with your IP being logged (Y)es/(N)o: Y
2.DNS驗證
Please deploy a DNS TXT record under the name
_acme-challenge.ngrok.yuzq.org with the following value:
2qFoaQCrnvyuvUNQGVR0TqnalVjrFmNAJMhlxDMnmCU
Before continuing, verify the record is deployed.
?
到域名管理后臺,添加一條txt解析記錄,主機記錄和記錄值再提示信息中,如下
?
?
解析記錄添加好了之后,再在控制臺中敲擊任意鍵進行驗證,最終得到證書
?
(2)自動驗證方式創建泛域名證書
注:不是所有的域名都能用自動驗證方式創建證書,僅支持以下域名供應商,如阿里云是沒有提供API來自動驗證
- certbot-dns-cloudflare
- certbot-dns-cloudxns
- certbot-dns-digitalocean
- certbot-dns-dnsimple
- certbot-dns-dnsmadeeasy
- certbot-dns-google
- certbot-dns-linode
- certbot-dns-luadns
- certbot-dns-nsone
- certbot-dns-ovh
- certbot-dns-rfc2136
- certbot-dns-route53
?
# ./certbot-auto certonly --standalone -n --agree-tos -m 393008735@qq.com --preferred-challenges http -d *.ngrok.yuzq.org
-n ?非交互式
--email? 指定賬戶
--agree-tos? 同意服務協議
-d? 參數為域名, 可以存在多個參數, 表示多個域名
-m? 參數為管理者郵箱
?
4.證書的有效期是90天,如果證書到期,可以重新更新
# ./certbot-auto renew
或
# /usr/local/webserver/cerbot/certbot-0.27.1/certbot-auto certonly --webroot -w /data/www/erp_doraemon_test/webapp -d erp.e10.cncn.net -d www.e10.cncn.net -d m.e10.cncn.net
?
也可以添加定時任務
# crontab -e
30 1 * * 1 ./www/server/certbot/certbot-auto renew >> /var/log/le-renew.log
每周一半夜1點30分執行renew任務
?
?
5.ngnix配置例子
server {
listen 80;
server_name yzq.ngrok.yuzq.org;
return 301 https://$server_name$request_uri;
}
?
server
{
listen 443 ssl;
server_name yzq.ngrok.yuzq.org;
index index.html index.php;
root /data/www/test;
?
include php56_ci.conf;
include extra.conf;
?
ssl on;
ssl_certificate /etc/letsencrypt/live/ngrok.yuzq.org/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/ngrok.yuzq.org/privkey.pem;
?
ssl_session_cache?shared:SSL:50m;
????ssl_session_timeout??30m;
????ssl_protocols?TLSv1?TLSv1.1?TLSv1.2;
????#ssl_ciphers?ECDHE-RSA-AES128-GCM-SHA256:ECDHE:ECDH:AES:HIGH:!NULL:!aNULL:!MD5:!ADH:!RC4:!DH:!DHE;
????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-AES256-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_prefer_server_ciphers?on;
?
location /static/ {
location ~ .*\.(php)?$
{
deny all;
}
}
location /static_m/ {
location ~ .*\.(php)?$
{
deny all;
}
}
?
location / {
if (!-e $request_filename) {
rewrite ^/(.*)$ /index.php/$1 last;
}
}
access_log /www/logs/web/test.log;
}
?
?
?
?
?
?
與50位技術專家面對面20年技術見證,附贈技術全景圖總結
以上是生活随笔為你收集整理的使用Certbot 生成 https 证书的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 应用服务器安装手册
- 下一篇: B-Tree和B+tree