在Ubuntu上獲取Let’s Encrypt證書的過程相對簡單
sudo apt update
sudo apt install certbot python3-certbot-apache
如果你使用的是Nginx服務器,請安裝python3-certbot-nginx
:
sudo apt install certbot python3-certbot-nginx
sudo certbot --apache
或者,如果你使用的是Nginx服務器:
sudo certbot --nginx
按照提示操作。Certbot將嘗試自動找到你的網站配置文件,并在驗證通過后自動獲取和安裝證書。如果需要,你還可以選擇手動指定證書文件的保存位置。
獲取成功后,你可以在Web服務器配置文件中添加證書信息。對于Apache服務器,你需要編輯/etc/apache2/sites-available/your_site.conf
文件,將SSLCertificateFile
和SSLCertificateKeyFile
指令指向Let’s Encrypt證書的路徑。對于Nginx服務器,你需要編輯/etc/nginx/sites-available/your_site
文件,將ssl_certificate
和ssl_certificate_key
指令指向Let’s Encrypt證書的路徑。
最后,重啟Web服務器以使更改生效:
對于Apache服務器:
sudo systemctl restart apache2
對于Nginx服務器:
sudo systemctl restart nginx
現在,你的Ubuntu服務器應該已經成功安裝了Let’s Encrypt證書,并通過HTTPS提供服務。請注意,Let’s Encrypt證書有效期為90天,因此需要定期更新。你可以使用sudo certbot renew
命令來檢查證書是否需要更新。