WordPress / linux / windows

certbot 設定說明 ssl

#常用記錄

#更新憑證
certbot renew

#建立憑證

certbot certonly --webroot --webroot-path=/var/www/letsencrypt -d www.tscs.com.tw -d en.tscs.com.tw -d ef.tscs.com.tw
server {
    listen 80;
    server_name _;
    location ^~ /.well-known/acme-challenge/ {
        root  /var/www/letsencrypt;
    }
    location / {
        return 301 https://$host$request_uri;
    }
}

#更新憑證後重啟nginx

vi /etc/letsencrypt/renewal-hooks/post/nginx_reload.sh

/etc/init.d/nginx reload

#刪除憑證
執行指令之後會詢問刪除那一個

certbot delete

#跳板更新背後的IIS(nginx–>iis)

server {
    listen 80;
    server_name mcyl.tscs.com.tw;
    location ^~ /.well-known/acme-challenge/ {
        proxy_pass http://10.3.1.32/.well-known/acme-challenge/;
    }
    location / {
        return 301 https://$host$request_uri;
    }
}

#用過mail server記錄

--測試區server
certbot certonly --webroot --webroot-path=/var/www/mail -d mail.tscs.com.tw --server https://acme-staging-v02.api.letsencrypt.org/directory
certbot certonly --webroot --webroot-path=/var/www/letsencrypt -d www.tscs.com.tw -d en.tscs.com.tw -d ef.tscs.com.tw
certbot certonly --webroot --webroot-path=/var/www/letsencrypt -d show-gift.com -d www.show-gift.com -d jp.show-gift.com -d it.show-gift.com

certonly 只生成證書,不做其他的協助設定
webroot 使用web站台的模式認證
webroot-path web路徑
https://acme-staging-v02.api.letsencrypt.org/directory 測試區
https://acme-v02.api.letsencrypt.org/directory 正式區

驗證路徑範例(只會用80 port)
http://mail.tscs.com.tw/.well-known/acme-challenge/**********

nginx設定

server {
       listen 80;
       server_name mail.tscs.com.tw smtp.tscs.com.tw;
       root /var/www/mail;
       location ^~ /.well-known/acme-challenge/ {
           default_type    "text/plain";
       }
       location / {
          return 301 https://$host$request_uri;
       }
}

萬用字元的憑證申請,缺點是無法renew(故棄用)

測試區
certbot -d tscs.com.tw -d *.tscs.com.tw --manual --preferred-challenges dns certonly --server https://acme-staging-v02.api.letsencrypt.org/directory

正式區
certbot -d tscs.com.tw -d *.tscs.com.tw --manual --preferred-challenges dns certonly --server https://acme-v02.api.letsencrypt.org/directory

renew hook (待測試)
vi /etc/letsencrypt/renewal/mail.tscs.com.tw.conf

# Options used in the renewal process
[renewalparams]
authenticator = webroot
account = 3a54644aa8d6477f3ac082b490a29374
server = https://acme-v02.api.letsencrypt.org/directory
renew_hook = systemctl reload nginx
[[webroot_map]]
jp.show-gift.com = /var/www/show_jp
www.show-gift.com = /var/www/show_www

多域名的申請範例

certbot certonly --webroot -w /var/www/show_www -d www.show-gift.com -d ww1.show-gift.com -w /var/www/show_jp -d jp1.show-gift.com -d jp2.show-gift.com

#關閉自動更新(尚在確認)

systemctl disable certbot
systemctl disable certbot.timer

發佈留言

發佈留言必須填寫的電子郵件地址不會公開。