一、基础准备:安装与启动Jellyfin
在Linux系统(以Ubuntu/CentOS为例)上,首先需要通过官方仓库安装Jellyfin并启动服务。
apt安装:sudo apt update
sudo apt install apt-transport-https ca-certificates curl
mkdir -p /etc/apt/keyrings
curl -fsSL https://repo.jellyfin.org/jellyfin_team.gpg.key | sudo gpg --dearmor -o /etc/apt/keyrings/jellyfin.gpg
echo "deb [signed-by=/etc/apt/keyrings/jellyfin.gpg] https://repo.jellyfin.org/ubuntu $(lsb_release -cs) main" | sudo tee /etc/apt/sources.list.d/jellyfin.sources
sudo apt update
sudo apt install jellyfin -y
sudo dnf update
sudo dnf install jellyfin -y
安装完成后,启动Jellyfin服务并设置开机自启:
sudo systemctl start jellyfin
sudo systemctl enable jellyfin
默认情况下,Jellyfin的Web界面运行在8096端口(HTTP)和8920端口(HTTPS)。
二、配置系统防火墙允许远程访问
Linux系统的防火墙(如Ubuntu的ufw、CentOS的firewalld)需开放Jellyfin的端口,否则外部无法访问。
sudo apt install ufw -y
sudo ufw allow 8096/tcp # 允许HTTP端口
sudo ufw allow 8920/tcp # 允许HTTPS端口
sudo ufw enable # 启用防火墙
sudo firewall-cmd --permanent --add-service=http
sudo firewall-cmd --permanent --add-service=https
sudo firewall-cmd --reload
若使用自定义端口,需将上述命令中的端口号替换为实际值。
三、配置Jellyfin允许远程连接
通过Jellyfin的Web界面开启远程访问功能:
http://SERVER_IP:8096),登录Jellyfin管理界面。bind_to_interface: 0.0.0.0(允许绑定到所有网络接口),可手动编辑配置文件(/etc/jellyfin/config/config.yaml)添加该参数,然后重启服务:sudo systemctl restart jellyfin
注:部分Linux发行版的Jellyfin配置文件路径可能为
/etc/jellyfin/jellyfin.conf,需根据实际情况调整。
四、配置反向代理(推荐,提升安全性与便利性)
反向代理(如Nginx/Apache)可将外部HTTPS请求转发到Jellyfin的HTTP端口,实现加密访问并隐藏内部端口。
sudo apt install nginx -y # Ubuntu
sudo dnf install nginx -y # CentOS
/etc/nginx/conf.d/jellyfin.conf):server {
listen 80;
server_name your_domain.com; # 替换为你的域名或公网IP
return 301 https://$host$request_uri; # 强制跳转HTTPS
}
server {
listen 443 ssl;
server_name your_domain.com;
ssl_certificate /path/to/your/certificate.crt; # 替换为SSL证书路径
ssl_certificate_key /path/to/your/private.key; # 替换为私钥路径
location / {
proxy_pass http://localhost:8096; # 转发到Jellyfin的HTTP端口
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}
}
sudo systemctl restart nginx
sudo apt install certbot python3-certbot-nginx -y # Ubuntu
sudo certbot --nginx -d your_domain.com # 自动配置SSL
https://your_domain.com访问Jellyfin。五、路由器端口转发(无公网IP时需此步骤)
若服务器位于局域网内(如家庭网络),需在路由器上设置端口转发,将外部请求转发到服务器的内部IP地址。
192.168.1.1或192.168.0.1访问)。80(HTTP)和443(HTTPS)(或自定义端口)。192.168.1.100)。8096(HTTP)和8920(HTTPS)。六、使用内网穿透工具(无公网IP的替代方案)
若无法配置路由器端口转发,可使用内网穿透工具(如cpolar、花生壳)将Jellyfin映射到公网。
wget https://github.com/cpolar/cpolar-linux-amd64.tar.gz
tar -xzf cpolar-linux-amd64.tar.gz
sudo cp cpolar-linux-amd64/cpolar /usr/local/bin
cpolar login
cpolar create --name jellyfin --local-port 8096 --protocol http
cpolar start jellyfin
https://xxxx.cpolar.io)访问Jellyfin。七、安全建议