1. 程式人生 > >使用 certbot 申請泛域名https證書

使用 certbot 申請泛域名https證書

posit encrypt cert 添加 ech 技術分享 sudo web 服務商

使用 certbot 申請泛域名https證書

Intro

Certbot 是一個基於 Let‘s Encrypt 的自動化申請證書的工具,支持的系統和web server也很多,詳見 Certbot 官網

Certbot 有一些 dns 插件可以自動化的不需要手動設置 dns 等方式來驗證域名的所屬,但是基本是一些國外的大型 DNS 提供商的,針對國內的話通過DNS驗證的話還是需要手動驗證DNS記錄,這裏主要介紹手動驗證,通過DNS插件自動驗證請參考 certbot 官網

手動驗證 DNS

  1. 安裝 Certbot,具體步驟參考官網

    $ sudo apt-get update
    $ sudo apt-get install software-properties-common
    $ sudo add-apt-repository universe
    $ sudo add-apt-repository ppa:certbot/certbot
    $ sudo apt-get update
    $ sudo apt-get install certbot python-certbot-nginx
  2. 申請 HTTPS 證書

    安裝好 certbot 之後,在命令行中執行以下命令:

    sudo certbot certonly  -d "*.weihanli.xyz" -d weihanli.xyz --manual --preferred-challenges dns-01  --server https://acme-v02.api.letsencrypt.org/directory

    執行完命令之後會提示需要記錄 IP 信息,需要同意不然不能繼續申請

  3. 設置 DNS TXT 記錄

    技術分享圖片

    按照提示,在自己的域名服務商那裏添加或者修改 _ache-challenge 的 txt 記錄,修改之後需要驗證是否解析成功,驗證方式詳見後面,驗證解析成功之後輸入 Enter 鍵繼續

  4. 證書申請成功

    技術分享圖片

    如果出現這樣的提示就說明證書已經申請成功了

  5. 配置 web server

    證書申請成功了就基本搞定了,有了證書之後就在服務器上配置一下就可以了

    nginx 配置示例:

    server {
      listen 80;
      listen 443;
      ssl_certificate            /etc/letsencrypt/live/weihanli.xyz/fullchain.pem;
      ssl_certificate_key      /etc/letsencrypt/live/weihanli.xyz/privkey.pem;
      if ($scheme = http) {
          return  301 https://$host$request_uri;
      }
      server_name weihanli.xyz;
    }

驗證 DNS TXT 記錄

windows 系統上在命令行或powershell中執行以下命令:

nslookup -q=txt _acme-challenge.weihanli.xyz

技術分享圖片

Reference

  • https://certbot.eff.org/
  • https://blogs.technet.microsoft.com/rmilne/2015/09/11/how-to-use-nslookup-to-check-dns-txt-record/
  • https://jingyan.baidu.com/article/fc07f98914db6c12fee51978.html

使用 certbot 申請泛域名https證書