在CentOS上為Jellyfin配置SSL證書,通常需要使用Let’s Encrypt提供的免費SSL/TLS證書。以下是配置步驟:
安裝Certbot: Certbot是一個自動化的工具,用于獲取和部署Let’s Encrypt SSL證書。首先,你需要安裝它。
sudo yum install epel-release
sudo yum install certbot python2-certbot-nginx
注意:CentOS 8的用戶可能需要安裝python3-certbot-nginx。
獲取SSL證書: 使用Certbot獲取SSL證書。由于Jellyfin通常不是直接通過Nginx或Apache等Web服務器訪問的,你需要使用Certbot的HTTP挑戰來獲取證書。
sudo certbot certonly --http-01-port=80 -d yourdomain.com -d www.yourdomain.com
將yourdomain.com和www.yourdomain.com替換為你的實際域名。Certbot會啟動一個臨時的Web服務器來驗證你對域名的控制權。
配置Jellyfin使用SSL: Jellyfin需要知道如何使用SSL證書。你可以通過編輯Jellyfin的配置文件來實現這一點。
打開Jellyfin的配置文件,通常位于/etc/jellyfin/config/config.xml。
sudo nano /etc/jellyfin/config/config.xml
在<server>標簽內添加或修改以下行:
<HttpPort>8096</HttpPort>
<HttpsPort>8443</HttpsPort>
<CertificateFile>/etc/letsencrypt/live/yourdomain.com/fullchain.pem</CertificateFile>
<PrivateKeyFile>/etc/letsencrypt/live/yourdomain.com/privkey.pem</PrivateKeyFile>
將yourdomain.com替換為你的實際域名,并確保路徑指向Certbot安裝的證書文件。
重啟Jellyfin服務: 保存配置文件并重啟Jellyfin服務以應用更改。
sudo systemctl restart jellyfin
配置防火墻: 如果你的服務器運行的是防火墻,確保開放HTTPS(通常是443端口)和Jellyfin使用的HTTP端口(在上面的配置中是8096)。
sudo firewall-cmd --permanent --zone=public --add-service=https
sudo firewall-cmd --permanent --zone=public --add-port=8096/tcp
sudo firewall-cmd --reload
自動續期證書: Let’s Encrypt證書有效期為90天,因此你需要設置一個cron作業或systemd定時器來自動續期證書。
Certbot通常會創建一個自動續期的定時器。你可以通過以下命令檢查其狀態:
sudo systemctl list-timers | grep certbot
如果一切正常,Certbot會在證書到期前30天內自動嘗試續期。
請注意,這些步驟可能會根據你的具體環境和Jellyfin版本有所不同。如果你遇到任何問題,請查閱Jellyfin的官方文檔或Certbot的相關指南。