在CentOS LAMP環境中配置SSL證書,可以按照以下步驟進行:
Certbot是一個用于獲取和部署Let’s Encrypt SSL證書的工具。首先,確保你的系統是最新的:
sudo yum update -y
然后安裝Certbot:
sudo yum install epel-release -y
sudo yum install certbot python2-certbot-apache -y
使用Certbot獲取SSL證書。假設你的域名是example.com
,你可以運行以下命令:
sudo certbot --apache -d example.com -d www.example.com
Certbot會自動配置Apache服務器并創建SSL證書。
Certbot會提示你驗證域名所有權。通常,它會創建一個臨時的HTTP文件或重定向到一個驗證頁面。按照提示完成驗證。
Let’s Encrypt的證書有效期為90天,因此需要設置自動續期。Certbot會自動為你設置一個cron任務來定期檢查并續期證書。
你可以手動測試續期過程:
sudo certbot renew --dry-run
如果沒有錯誤,說明配置正確。
確保你的防火墻允許HTTPS流量:
sudo firewall-cmd --permanent --zone=public --add-service=https
sudo firewall-cmd --reload
最后,重啟Apache服務器以應用新的SSL配置:
sudo systemctl restart httpd
打開瀏覽器,訪問https://example.com
,確保瀏覽器顯示安全鎖圖標,并且證書信息正確。
如果你使用的是Nginx而不是Apache,可以參考以下步驟:
sudo yum install epel-release -y
sudo yum install certbot python-certbot-nginx -y
sudo certbot --nginx -d example.com -d www.example.com
Certbot會自動配置Nginx服務器并創建SSL證書。
Certbot會提示你驗證域名所有權。按照提示完成驗證。
Certbot會自動為你設置一個cron任務來定期檢查并續期證書。
sudo systemctl restart nginx
打開瀏覽器,訪問https://example.com
,確保瀏覽器顯示安全鎖圖標,并且證書信息正確。
通過以上步驟,你應該能夠在CentOS LAMP環境中成功配置SSL證書。