目錄
文章
分類
標籤
AI ai android Bitbucket C# C++ Certbot ChatGPT Cloudflare Code Runner CPE CPU排程 cron Daphne Django DNS設定 Docker fused-location Git GPT HTML HTTPS kotlin Line Bot Linux location-app Mac macOS MySQL n8n Next.js Nginx OpenAI permissions Python Python Django Pytorch pytorch PyTorch rclone React Redis Replit SSL streamlit Swap Ubuntu Unity Vector VM設定 VSCode WebSocket WordPress Wordpress wordpress-備份 yolo 中位數 伺服器設定 修復 最佳住址 利率 前端 動態生成 即時通訊 卷積神經網路 場景切換 學習 安全性 專案管理 帳號建立 影像分類 後台 性能 惡意軟體 成績查詢 投資 排序 操作系統 效率 教學 殖利率 深度學習 演算法 版本控制 物件偵測 神經網絡 程式解題 程式設計 競程 系統管理 終端機 統計 網頁框架 股票 自動化 財務 資料共享 資料結構 距離計算 路由 遊戲開發 選單 部署 開發 開發技巧 開發環境 開發者 雲端備份 靜態文件
目錄
目錄
550 字
3 分鐘
Nginx + Certbot 為 WordPress 網站設定 HTTPS
本教學將說明如何透過 Certbot 申請 Let’s Encrypt 免費 SSL 憑證,並整合至 Nginx,成功為你的 WordPress 網站啟用 HTTPS。
📌 前置準備
-
網站程式碼已部署於
/var/www/你的網站資料夾 -
網域名稱(例如
yourdomain.com)已正確指向你的伺服器 IP -
已安裝 Nginx、PHP-FPM、Certbot
步驟一:建立 Nginx 設定檔
使用 nano 編輯對應網域的 Nginx 設定檔:
1sudo nano /etc/nginx/sites-available/yourdomain.comBash
設定內容範例如下(HTTPS 區塊會由 Certbot 自動補上):
1server {2 server_name yourdomain.com www.yourdomain.com;3
4 root /var/www/你的網站資料夾;5 index index.php index.html;6
7 access_log /var/log/nginx/yourdomain.access.log;8 error_log /var/log/nginx/yourdomain.error.log;9
10 location / {11 try_files $uri $uri/ /index.php?$args;12 }13
14 location ~ \.php$ {15 include snippets/fastcgi-php.conf;16 fastcgi_pass unix:/run/php/php8.3-fpm.sock;17 }18
19 location ~ /\.ht {20 deny all;21 }22
23 listen 443 ssl; # managed by Certbot24 ssl_certificate /etc/letsencrypt/live/yourdomain.com/fullchain.pem; # managed by Certbot25 ssl_certificate_key /etc/letsencrypt/live/yourdomain.com/privkey.pem; # managed by Certbot26 include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot27 ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot28}29
30server {31 if ($host = www.yourdomain.com) {32 return 301 https://$host$request_uri;33 } # managed by Certbot34
35 if ($host = yourdomain.com) {36 return 301 https://$host$request_uri;37 } # managed by Certbot38
39 listen 80;40 server_name yourdomain.com www.yourdomain.com;41 return 404; # managed by Certbot42}Bash
啟用站點:
1sudo ln -s /etc/nginx/sites-available/yourdomain.com /etc/nginx/sites-enabled/2
3ps: 注意你的fastcgi_pass php 版本要對應 例如我是php8.3-fpm.sock步驟二:使用 Certbot 啟用 HTTPS
使用以下指令安裝 SSL 憑證並自動設定 Nginx:
1sudo certbot --nginx -d yourdomain.com -d www.yourdomain.com1sudo certbot --nginx -d yourdomain.com -d www.yourdomain.comBash
若成功,會出現類似以下訊息:
1Successfully deployed certificate for yourdomain.com to /etc/nginx/sites-enabled/yourdomain.com2...3Congratulations! You have successfully enabled HTTPS on https://yourdomain.com1Successfully deployed certificate for yourdomain.com to /etc/nginx/sites-enabled/yourdomain.com2...3Congratulations! You have successfully enabled HTTPS on https://yourdomain.comBash
步驟三:檢查 Nginx 設定
確認設定檔是否正確:
1sudo nginx -t1sudo nginx -tBash
重新載入 Nginx:
1sudo systemctl reload nginx1sudo systemctl reload nginxBash
步驟四:確認 HTTPS 連接埠(443)已開啟
檢查 443 port 是否啟用中:
1sudo ss -tulpn | grep ':443'1sudo ss -tulpn | grep ':443'Bash
若防火牆未開啟 443,請加入防火牆規則:
1sudo ufw allow 4432sudo ufw reload1sudo ufw allow 4432sudo ufw reloadBash
可再次確認 UFW 狀態:
1sudo ufw status1sudo ufw statusBash
步驟五:確認網站正常運作
瀏覽器開啟:
應顯示 WordPress 首頁,且網址列應顯示鎖頭圖示(HTTPS 已啟用)。
✅ 補充資訊
-
Certbot 預設會自動排程憑證續期,無需手動干預
-
憑證有效期限為 90 天,自動續期機制會確保不中斷
-
可手動測試續期機制:
sudo certbot renew --dry-run
Nginx + Certbot 為 WordPress 網站設定 HTTPS
/posts/nginx--certbot-為-wordpress-網站設定-https/ 部分資訊可能已經過時
目錄
文章
分類
標籤
AI ai android Bitbucket C# C++ Certbot ChatGPT Cloudflare Code Runner CPE CPU排程 cron Daphne Django DNS設定 Docker fused-location Git GPT HTML HTTPS kotlin Line Bot Linux location-app Mac macOS MySQL n8n Next.js Nginx OpenAI permissions Python Python Django Pytorch pytorch PyTorch rclone React Redis Replit SSL streamlit Swap Ubuntu Unity Vector VM設定 VSCode WebSocket WordPress Wordpress wordpress-備份 yolo 中位數 伺服器設定 修復 最佳住址 利率 前端 動態生成 即時通訊 卷積神經網路 場景切換 學習 安全性 專案管理 帳號建立 影像分類 後台 性能 惡意軟體 成績查詢 投資 排序 操作系統 效率 教學 殖利率 深度學習 演算法 版本控制 物件偵測 神經網絡 程式解題 程式設計 競程 系統管理 終端機 統計 網頁框架 股票 自動化 財務 資料共享 資料結構 距離計算 路由 遊戲開發 選單 部署 開發 開發技巧 開發環境 開發者 雲端備份 靜態文件
目錄