免費SSL證書製做-Lets Encrypt

騰訊雲一年的免費SSL證書到期了,在老大的推薦下看了一下Let's Encrypt 家的免費證書,雖然只有三個月,可是支持免費續期,並且支持通配符證書,這卻是很大的福利了nginx

首先聲明,個人系統是CentOS7 ,系統不一致,可自行Google其餘或直接官網教程https://certbot.eff.org/lets-encrypt/centosrhel7-nginxshell

下載certbot

$ wget https://dl.eff.org/certbot-auto
$ chmod +x certbot-auto

製做通配符證書

$ ./certbot-auto certonly  -d "*.example.com" -d "example.com"  --manual --preferred-challenges dns-01  --server https://acme-v02.api.letsencrypt.org/directory

這裏會自動運行yum安裝必要的包,而後會提示以下centos

Please choose an account
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
1: dev_test@2016-04-18T23:21:19Z (911e)
2: ip-10-164-131-233.ap-southeast-1.compute.internal@2016-06-13T11:02:16Z (5c1b)
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Select the appropriate number [1-2] then [enter] (press 'c' to cancel): 1
Obtaining a new certificate
Performing the following challenges:
dns-01 challenge for example.com
dns-01 challenge for example.com

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NOTE: The IP of this machine will be publicly logged as having requested this
certificate. If you're running certbot in manual mode on a machine that is not
your server, please ensure you're okay with that.

Are you OK with your IP being logged?
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
(Y)es/(N)o: Y

注意這裏api

Please deploy a DNS TXT record under the name
_acme-challenge.example.com with the following value:

e35fqmCZcB8L56ID4801hlA3aLx3viXtZo1yA3WVSmg

Before continuing, verify the record is deployed.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Press Enter to Continue

須要在後臺域名解析以後再按Enter安全

製做完成後,將製做後的證書拿過用便可服務器

配置以下app

ssl_certificate cert/fullchain1.pem;
     ssl_certificate_key cert/privkey1.pem;
     ssl_trusted_certificate cert/chain1.pem;

重啓後就能看到HTTPS的安全綠色小球了post

續期

上面提到了,這個證書有效期只有三個月,因此須要定時從新生成新的證書,而後完成後重啓nginx測試

完整命令:certbot-auto renew [--cert-name CERTNAME] [options]
可選參數:ui

  • --cert-name CERTNAME:指定要更新的證書。Certbot 用這個名稱來管理證書文件。名稱不影響證書內容。能夠用 certbot certificates 命令查看證書名。
  • --dry-run:用於測試,只獲取測試證書,不保存至磁盤。只有 certonly 和 renew 兩個子命令能夠用這個參數。仍然會會改寫 Apache 或 Nginx 服務器的配置文件並重啓服務器。仍然會調用 --pre-hook--post-hook 命令(只要定義過)。只是再也不調用 --deploy-hook 命令。
  • --force-renewal, --renew-by-default:強制更新域名的證書,即便離過時時間還遠得很。
  • --allow-subset-of-names:在域名全部權認證時,即便認證失敗,也產生證書。在更新多個域名時有效,由於有可能部分域名再也不指向當前主機。注意:不能和參數 --csr 同時使用。
  • -q, --quiet:靜默執行。
  • --debug-challenges:調試模式,提交至 CA 前須要用戶確認。
  • --preferred-challenges:驗證域名全部權的方式,」dns」 或 「tls-sni-01,http,dns」 等。每一個服務器插件支持有限種類的方式。
  • --pre-hook PRE_HOOK:在獲取證書前要執行的 shell 命令。好比暫時關閉服務器軟件以防止可能的衝突。只有在自動獲取/更新證書時纔會執行。若是更新多個證書時,只執行第一個命令。
  • --post-hook POST_HOOK:在獲取證書後要執行的 shell 命令。好比部署新證書,或重啓服務器軟件。若是更新多個證書時,只執行第一個命令。
  • --deploy-hook DEPLOY_HOOK:每一個有效的認證都會觸發一次的 shell 命令。對這個命令,shell 變量 $RENEWED_LINEAGE 表示包含域名證書和私鑰的配置目錄,好比 /etc/letsencrypt/live/example.com$RENEWED_DOMAINS 表示空格分隔的剛更新的域名列表,好比 example.com www.example.com
  • --disable-hook-validation:驗證 --pre-hook/--post-hook/--deploy-hook 的 shell 命令是否有效,提早發現錯誤。
  • --no-directory-hooks:更新證書時不執行 hook 目錄中的命令。

寫個腳本加入到定時任務裏面便可

相關文章
相關標籤/搜索