首先确保CentOS系统已更新,并安装Jellyfin及其依赖。以CentOS Stream 9为例,可通过官方仓库直接安装:
sudo dnf update -y
sudo dnf install -y epel-release
sudo dnf install -y jellyfin
安装完成后,Jellyfin服务会自动启动(若未启动,可通过systemctl start jellyfin手动启动)。
Jellyfin默认使用8096端口(HTTP)和8920端口(HTTPS),需通过firewalld开放这些端口:
sudo firewall-cmd --permanent --add-port=8096/tcp # 开放HTTP端口
sudo firewall-cmd --permanent --add-port=8920/tcp # 开放HTTPS端口
sudo firewall-cmd --reload # 重新加载防火墙规则
若使用其他端口(如自定义端口),需将上述命令中的端口号替换为实际使用的端口。
若系统启用了SELinux(默认启用),需允许Jellyfin绑定到网络端口。临时测试可执行:
sudo setenforce 0 # 将SELinux设为宽容模式(不持久化)
若需永久生效,需修改SELinux策略或安装对应模块(如jellyfin的SELinux策略包)。
通过Web界面或配置文件启用远程访问:
http://服务器IP:8096,登录后进入设置 > 远程访问,勾选“启用远程访问”,可选择“开启自动端口映射”(需路由器支持UPnP)或自定义端口。/etc/jellyfin/config/config.yaml),修改以下参数:allow_remote: true # 允许远程访问
bind_to_interface: 0.0.0.0 # 绑定到所有网络接口
https_port: 8920 # HTTPS端口(若使用HTTPS)
保存后重启Jellyfin服务:sudo systemctl restart jellyfin
为提升安全性(如启用HTTPS、隐藏真实端口),建议使用Nginx作为反向代理:
sudo dnf install -y nginx
sudo systemctl start nginx
sudo systemctl enable nginx
/etc/nginx/conf.d/jellyfin.conf,添加以下内容:server {
listen 80;
server_name your_domain.com; # 替换为你的域名或IP
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;
}
}
重启Nginx使配置生效:sudo systemctl restart nginx
为避免数据传输被窃听,建议为Jellyfin配置SSL证书(如Let’s Encrypt):
sudo dnf install -y certbot python3-certbot-nginx
sudo certbot --nginx -d your_domain.com # 替换为你的域名
Certbot会自动配置Nginx的HTTPS监听(默认443端口)及证书续期。https://your_domain.com访问Jellyfin;http://服务器IP:8096或https://服务器IP:8920访问(需确保端口已开放)。sudo firewall-cmd --permanent --add-rich-rule='rule family="ipv4" source address="192.168.1.100" port protocol="tcp" port="8096" accept');通过以上步骤,即可在CentOS上实现Jellyfin的远程访问,并兼顾安全性与稳定性。