差異處

這裏顯示兩個版本的差異處。

連向這個比對檢視

兩邊的前次修訂版 前次修改
下次修改
前次修改
tech:ssl_letsencrypt [2020/12/06 12:45] – [CentOS 8] jonathantech:ssl_letsencrypt [2022/07/20 14:40] (目前版本) – [apache 相關設定] jonathan
行 4: 行 4:
  
 ===== 申請 Let's Encrypt 與設定 Web Server 程序 ===== ===== 申請 Let's Encrypt 與設定 Web Server 程序 =====
-  * 下載 Let's Encrypt certbot 工具 +{{tabinclude>tech:ssl_letsencrypt:ubuntu20_04, tech:ssl_letsencrypt:alpine3_15, tech:ssl_letsencrypt:centos8, tech:ssl_letsencrypt:centos7}}
-    * CentOS 8<cli> +
-dnf install certbot +
-</cli> +
-    * CentOS 7<code sh> +
-yum install certbot +
-</code>+
  
-  * 執行 certbot 工具 
-    * 使用 Apache 環境執行語法  
-      * CentOS 7<code sh> 
-yum install python-certbot-apache 
-certbot --apache  
-</code> 
-    * 使用 Nginx 環境執行語法  
-      * CentOS 8<cli> 
-dnf install python3-certbot-nginx 
-</cli> 
-      * CentOS 7<code sh> 
-yum install python-certbot-nginx 
-certbot --nginx 
-</code> 
     * 這過程會檢查與安裝 python packages 並讀取 web server 的設定, 查看目前的網站網址, 如果有設定 Virtual Host 多網址, 也可以選擇產生多網域的憑證((只產生一個憑證檔案, 但該憑證檔案內有包含多個網址))     * 這過程會檢查與安裝 python packages 並讀取 web server 的設定, 查看目前的網站網址, 如果有設定 Virtual Host 多網址, 也可以選擇產生多網域的憑證((只產生一個憑證檔案, 但該憑證檔案內有包含多個網址))
     * 原則上只要最後詢問 Please choose whether or not to redirect HTTP traffic to HTTPS, removing HTTP access. 是否要讓瀏覽 http 網址自動轉至 https 的問題後, 出現以下的訊息, 就表示已自動將 web server 的設定都改好<file>     * 原則上只要最後詢問 Please choose whether or not to redirect HTTP traffic to HTTPS, removing HTTP access. 是否要讓瀏覽 http 網址自動轉至 https 的問題後, 出現以下的訊息, 就表示已自動將 web server 的設定都改好<file>
行 60: 行 40:
 #</VirtualHost> #</VirtualHost>
 </file> </file>
-  * certbot-auto 會自動產生 /etc/httpd/conf/httpd-le-ssl.conf 定義 VirtualHost+  * certbot-auto 會自動產生 /etc/httpd/conf/httpd-le-ssl.conf 定義 VirtualHost, 如果沒有產生要直接修改 ssl.conf ++點這裡看 wiki.ichiayi.com 範例|<file> 
 +
 +
 +    # Explictly disable SSL compression (should default to off anyway...) 
 +    # Note enabling SSL compression makes Apache vulnerable to CRIME attack. 
 +    SSLCompression off 
 + 
 +    # Default certificate file to use (provided by TurnKey) 
 +    #SSLCertificateFile /etc/ssl/private/cert.pem 
 +    SSLCertificateFile /etc/letsencrypt/live/wiki.ichiayi.com/cert.pem 
 +    SSLCertificateKeyFile /etc/letsencrypt/live/wiki.ichiayi.com/privkey.pem 
 + 
 +</IfModule> 
 +</file>
 <note> <note>
   * 如果之後增加 VirtualHost 透過 <code sh>certbot-auto --apache certonly</code> 產生憑證後, 需要到 /etc/httpd/conf/httpd-le-ssl.conf 手動加上定義    * 如果之後增加 VirtualHost 透過 <code sh>certbot-auto --apache certonly</code> 產生憑證後, 需要到 /etc/httpd/conf/httpd-le-ssl.conf 手動加上定義 
行 224: 行 217:
 ===== 透過 CloudFlare DNS 自動更新無 Web 對外網站 SSL 憑證 ===== ===== 透過 CloudFlare DNS 自動更新無 Web 對外網站 SSL 憑證 =====
   * 因為部份網站是內部網站, 並無法對外透過 Web 方式認證自動更新憑證, 所以需要透過 DNS 即時建立 TXT Record 來認證, 如要自動認證, 就需要透過 DNS 提供整合 API 才能達成   * 因為部份網站是內部網站, 並無法對外透過 Web 方式認證自動更新憑證, 所以需要透過 DNS 即時建立 TXT Record 來認證, 如要自動認證, 就需要透過 DNS 提供整合 API 才能達成
- +{{tabinclude>tech:ssl_letsencrypt:cf_ubuntu20_04, tech:ssl_letsencrypt:cf_centos8, tech:ssl_letsencrypt:cf_centos7, tech:ssl_letsencrypt:cf_centos6}}
-==== CentOS 8 ==== +
-  * 安裝 DNS CloudFlare Plugin<cli> +
-dnf install python3-certbot-dns-cloudflare +
-</cli> +
-  * 建立 /root/lets-encrypt/cloudflare.ini <cli> +
-mkdir -p /root/lets-encrypt/ +
-vi /root/lets-encrypt/cloudflare.ini +
-</cli>Exp:<file> +
-# Cloudflare API credentials used by Certbot +
-dns_cloudflare_email = [email protected] +
-dns_cloudflare_api_key = 0123456789abcdef0123456789abcdef01234567 +
-</file> +
-  * 設定保護權限 <cli> +
-chmod 600 /root/lets-encrypt/cloudflare.ini +
-</cli> +
-  * 進行申請新憑證 Exp. example.com <code sh> +
-/usr/bin/certbot certonly \ +
-  --dns-cloudflare \ +
-  --dns-cloudflare-credentials /root/lets-encrypt/cloudflare.ini \ +
-  --dns-cloudflare-propagation-seconds 10 \ +
-  -d example.com +
-</code> +
-  * 進行定期更新憑證 Exp. example.com <cli> +
-/usr/bin/certbot renew \ +
-  --dns-cloudflare \ +
-  --dns-cloudflare-credentials /root/lets-encrypt/cloudflare.ini \ +
-  --dns-cloudflare-propagation-seconds 10 +
-</cli> +
-  * 設定每天自動檢查更新  +
-    - 建立 /root/lets-encrypt/renewcert.sh <cli> +
-vi /root/lets-encrypt/renewcert.sh</cli><file> +
-/usr/bin/certbot renew \ +
-  --dns-cloudflare \ +
-  --dns-cloudflare-credentials /root/lets-encrypt/cloudflare.ini \ +
-  --dns-cloudflare-propagation-seconds 10 +
-</file><cli> +
-chmod a+x /root/lets-encrypt/renewcert.sh +
-</cli> +
-    - 設定 /etc/crontab<cli> +
-vi /etc/crontab</cli><file> +
-+
-# let's encrypt +
-35 2 * * * root /root/lets-encrypt/renewcert.sh > /tmp/renewcert.log +
-</file><cli> +
-systemctl restart crond +
-</cli> +
- +
-==== CentOS 7 ==== +
-  * 安裝 DNS CloudFlare Plugin<code sh> +
-yum install python2-certbot-dns-cloudflare +
-</code> +
-  * 建立 /root/lets-encrypt/cloudflare.ini <code sh>mkdir -p /root/lets-encrypt/</code>Exp:<file> +
-# Cloudflare API credentials used by Certbot +
-dns_cloudflare_email = [email protected] +
-dns_cloudflare_api_key = 0123456789abcdef0123456789abcdef01234567 +
-</file> +
-  * 設定保護權限 <code sh> +
-chmod 600 /root/lets-encrypt/cloudflare.ini +
-</code> +
-  * 進行申請新憑證 Exp. example.com <code sh> +
-/usr/bin/certbot certonly \ +
-  --dns-cloudflare \ +
-  --dns-cloudflare-credentials /root/lets-encrypt/cloudflare.ini \ +
-  --dns-cloudflare-propagation-seconds 10 \ +
-  -d example.com +
-</code> +
-  * 進行定期更新憑證 Exp. example.com <code sh> +
-/usr/bin/certbot renew \ +
-  --dns-cloudflare \ +
-  --dns-cloudflare-credentials /root/lets-encrypt/cloudflare.ini \ +
-  --dns-cloudflare-propagation-seconds 10 +
-</code> +
-  * 設定每天自動檢查更新  +
-    - 建立 /root/lets-encrypt/renewcert.sh <code sh> +
-vi /root/lets-encrypt/renewcert.sh</code><file> +
-/usr/bin/certbot renew \ +
-  --dns-cloudflare \ +
-  --dns-cloudflare-credentials /root/lets-encrypt/cloudflare.ini \ +
-  --dns-cloudflare-propagation-seconds 10 +
-</file><code sh> +
-chmod a+x /root/lets-encrypt/renewcert.sh +
-</code> +
-    - 設定 /etc/crontab<code sh> +
-vi /etc/crontab</code><file> +
-+
-# let's encrypt +
-35 2 * * * root /root/lets-encrypt/renewcert.sh > /tmp/renewcert.log +
-</file><code sh> +
-systemctl restart crond +
-</code> +
- +
-==== CentOS 6 ==== +
-  - 建立 /root/lets-encrypt/authenticator.sh<code sh> +
-cd /root/lets-encrypt/ +
-wget https://svn.ichiayi.com/opensvn/opentrysoft/certbot/authenticator.sh +
-chmod a+x authenticator.sh +
-</code> +
-  - 建立 /root/lets-encrypt/cleanup.sh<code sh> +
-cd /root/lets-encrypt/ +
-wget https://svn.ichiayi.com/opensvn/opentrysoft/certbot/cleanup.sh +
-chmod a+x cleanup.sh</code> +
-  - 取得 CloudFlare 的 Zone ID 與 Global API Key 更改 authenticator.sh 與 cleanup.sh 內容<file> +
-+
-API_KEY="xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" +
-EMAIL="[email protected]" +
-ZONE_ID="xxxxxxxxxxxxxxx" +
-+
-</file>++看 CloudFlare 取得 Zone ID / Global API Key 畫面| {{:tech:2019031501.png}} \\ {{:tech:2019031502.png}} \\ {{:tech:2019031503.png}} \\ {{:tech:2019031504.png}} \\ {{:tech:2019031505.png}}++ +
-  - 執行取得 SSL 憑證命令 Exp. erp.ichiayi.com <code sh> +
-/root/lets-encrypt/certbot-auto certonly --manual --preferred-challenges=dns --manual-auth-hook /root/lets-encrypt/authenticator.sh --manual-cleanup-hook /root/lets-encrypt/cleanup.sh -d erp.ichiayi.com +
-</code> +
-  * 設定憑證到期自動更新 +
-    - 建立 /root/lets-encrypt/renewcert.sh Exp. erp.ichiayi.com <code sh> +
-vi /root/lets-encrypt/renewcert.sh</code><file> +
-/root/lets-encrypt/certbot-auto renew --preferred-challenges=dns --manual-auth-hook /root/lets-encrypt/authenticator.sh --manual-cleanup-hook /root/lets-encrypt/cleanup.sh --agree-tos +
-</file> +
-    - 設定執行權限<code sh> +
-chmod a+x /root/lets-encrypt/renewcert.sh +
-</code> +
-    - 設定每天 4:30 執行自動檢查一次<code sh> +
-vi /etc/crontab +
-</code><file> +
-+
-# erp.ichiayi.com SSL cert auto renew +
-30 4 * * * root /root/lets-encrypt/renewcert.sh > /tmp/certrenew.log +
-</file><code sh> +
-service crond restart +
-</code>+
  
 ===== 參考網址 ===== ===== 參考網址 =====
   * https://certbot.eff.org/lets-encrypt/centos6-apache   * https://certbot.eff.org/lets-encrypt/centos6-apache
   * https://certbot.eff.org/lets-encrypt/centosrhel7-other   * https://certbot.eff.org/lets-encrypt/centosrhel7-other
 +  * https://gitpress.io/@chchang/ubuntu-letsencrypt-cloudflare-wildcard
 +  * https://blog.anzupop.com/posts/acquire-lets-encrypt-certs-using-dns-cloudflare-plugin/
   * https://serverfault.com/questions/744960/configuring-ssl-with-virtual-hosts-under-apache-and-centos   * https://serverfault.com/questions/744960/configuring-ssl-with-virtual-hosts-under-apache-and-centos
   * https://sslmate.com/caa/   * https://sslmate.com/caa/
  • tech/ssl_letsencrypt.1607229928.txt.gz
  • 上一次變更: 2020/12/06 12:45
  • jonathan