溫馨提示×

ubuntu letsencrypt與nginx適配

小樊
120
2024-12-31 17:54:27
欄目: 智能運維

Let’s Encrypt 是一個免費的 SSL/TLS 證書頒發機構,它可以幫助你為你的網站提供 HTTPS 安全連接

  1. 安裝 Certbot 和 Nginx:
sudo apt update
sudo apt install certbot python3-certbot-nginx
  1. 獲取并安裝證書:
sudo certbot --nginx -d yourdomain.com -d www.yourdomain.com

yourdomain.comwww.yourdomain.com 替換為你的域名。Certbot 將自動檢測你的 Nginx 配置文件,并在 /etc/nginx/sites-available/ 目錄下創建一個新的配置文件。

  1. 檢查 Nginx 配置文件的語法:
sudo nginx -t

如果配置文件沒有問題,你將看到以下輸出:

nginx: configuration file /etc/nginx/nginx.conf test is successful
  1. 重新加載 Nginx 以應用更改:
sudo systemctl reload nginx

現在,你的網站應該已經通過 Let’s Encrypt 獲得了 SSL/TLS 證書,并且可以通過 HTTPS 訪問了。

注意:Let’s Encrypt 的證書有效期為 90 天,因此你需要定期更新證書。你可以使用 sudo certbot --nginx 命令來更新證書。此外,你還可以設置自動更新證書,以便 Certbot 在證書即將過期時自動更新它們。要設置自動更新,請運行以下命令:

sudo certbot --nginx --renew-hook "/etc/letsencrypt/renewal/yourdomain.com.sh"

yourdomain.com.sh 替換為一個腳本文件名,該腳本將在證書更新后執行。確保該腳本具有可執行權限:

sudo chmod +x /etc/letsencrypt/renewal/yourdomain.com.sh

0
亚洲午夜精品一区二区_中文无码日韩欧免_久久香蕉精品视频_欧美主播一区二区三区美女