X

Debian Linux 使用 certbot 申請 Wildcard SSL

想要使用 Let's Encrypt 申請 Wildcard 的 SSL (HTTPS) 憑證,又不想用 snapd。

  • 註1:想使用 apt 的 certbot 來申請,要怎麼做?
  • 註2:系統為 Debian Linux Buster (10)

Debian Linux 使用 certbot 申請 Wildcard SSL

若想使用 snap 的話,可以參考官網步驟:Certbot

Nginx 的設定可以參考此篇:Let's Encrypt 安裝 與 Nginx 設定

使用 certbot 申請 Let's Encrypt 的 Wildcard SSL 步驟

此次 Let's Encrypt 使用 DNS 驗證模式

  1. apt install certbot
  2. sudo certbot certonly --manual --preferred-challenges=dns --email youremail@gmail.com --server https://acme-v02.api.letsencrypt.org/directory --agree-tos -d example.com -d *.example.com
    • 設定 DNS 要設定兩組 TXT (會出現兩次,要設定兩組)
  3. 再來就完成,會得到下述憑證:
    • /etc/letsencrypt/live/example.com/fullchain.pem
    • /etc/letsencrypt/live/example.com/privkey.pem
  4. 三個月內要更新憑證:sudo certbot renew
  5. 另外需要 hdparm.pem 的製作方式:sudo openssl dhparam -out /etc/nginx/ssl.crt/dhparam.pem 2048

設定 Nginx SSL

  1. vim /etc/nginx/sites-enabled/example.com.conf
    server {
        listen 80;
        server_name site1.example.com;
        rewrite ^(.*) https://$server_name$1 permanent;
    }
    
    server {
        listen 443 ssl;
        server_name site1.example.com;
        root /var/www/html/;
    
        access_log /var/log/nginx/site1-example-com.access.log combined;
        error_log /var/log/nginx/site1-example-com.error.log crit;
    
        ssl_certificate /etc/letsencrypt/live/example.com/fullchain.pem;      
        ssl_certificate_key /etc/letsencrypt/live/example.com/privkey.pem;
        ssl_dhparam /etc/nginx/ssl.crt/dhparams.pem; # sudo openssl dhparam -out /etc/ssl/certs/dhparam.pem 2048
        ssl_session_timeout 5m;
        ssl_session_cache shared:SSL:5m;
        ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
        ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-AES256-GCM-SHA384:DHE-RSA-AES128-GCM-SHA256:DHE-DSS-AES128-GCM-SHA256:kEDH+AESGCM:ECDHE-RSA-AES128-SHA256:ECDHE-ECDSA-AES128-SHA256:ECDHE-RSA-AES128-SHA:ECDHE-ECDSA-AES128-SHA:ECDHE-RSA-AES256-SHA384:ECDHE-ECDSA-AES256-SHA384:ECDHE-RSA-AES256-SHA:ECDHE-ECDSA-AES256-SHA:DHE-RSA-AES128-SHA256:DHE-RSA-AES128-SHA:DHE-DSS-AES128-SHA256:DHE-RSA-AES256-SHA256:DHE-DSS-AES256-SHA:DHE-RSA-AES256-SHA:AES128-GCM-SHA256:AES256-GCM-SHA384:AES128-SHA256:AES256-SHA256:AES128-SHA:AES256-SHA:AES:CAMELLIA:DES-CBC3-SHA:!aNULL:!eNULL:!EXPORT:!DES:!RC4:!MD5:!PSK:!aECDH:!EDH-DSS-DES-CBC3-SHA:!EDH-RSA-DES-CBC3-SHA:!KRB5-DES-CBC3-SHA; ssl_prefer_server_ciphers on;
    }
  2. sudo systemctl restart nginx.service
  3. 就可以測試連線 https://site1.example.com 囉~
Tsung: 對新奇的事物都很有興趣, 喜歡簡單的東西, 過簡單的生活.
Related Post