在Ubuntu上配置Apache SSL證書可以通過以下步驟完成。我們將使用Let’s Encrypt提供的免費SSL證書。以下是詳細步驟:
Certbot是一個自動化的工具,用于獲取和續訂Let’s Encrypt證書。
sudo apt update
sudo apt install certbot python3-certbot-apache
運行Certbot來獲取SSL證書。假設你的域名是example.com。
sudo certbot --apache -d example.com -d www.example.com
Certbot會自動配置Apache并創建必要的SSL配置文件。
Certbot會提示你驗證域名所有權。通常,它會創建一個臨時的HTTP-01挑戰文件,并將其放在你的網站根目錄下。你需要確保這個文件可以通過瀏覽器訪問。
打開瀏覽器,訪問http://example.com/.well-known/acme-challenge/,你應該能看到一個驗證頁面。
驗證成功后,Certbot會自動更新Apache配置文件以啟用SSL。你可以檢查Apache配置文件以確保一切正常。
sudo nano /etc/apache2/sites-available/example.com-le-ssl.conf
確保配置文件中有以下內容:
<VirtualHost *:443>
ServerAdmin webmaster@localhost
DocumentRoot /var/www/html
SSLEngine on
SSLCertificateFile /etc/letsencrypt/live/example.com/fullchain.pem
SSLCertificateKeyFile /etc/letsencrypt/live/example.com/privkey.pem
Include /etc/letsencrypt/options-ssl-apache.conf
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
確保你的SSL站點配置文件已啟用。
sudo a2ensite example.com-le-ssl.conf
重啟Apache以應用更改。
sudo systemctl restart apache2
打開瀏覽器,訪問https://example.com,你應該能看到一個安全的連接,并且瀏覽器地址欄會顯示鎖形圖標。
Let’s Encrypt證書每90天需要續訂一次。Certbot會自動處理續訂過程,但你可以手動測試續訂。
sudo certbot renew --dry-run
如果沒有錯誤,Certbot會在到期前自動續訂證書。
通過以上步驟,你就可以在Ubuntu上成功配置Apache SSL證書。