温馨提示×

centos如何限制jellyfin的访问权限

小樊
41
2025-10-15 06:31:45
栏目: 智能运维

在CentOS上限制Jellyfin的访问权限,可以通过多种方式实现,包括使用防火墙规则、配置HTTP基本认证、使用反向代理服务器(如Nginx或Apache)等。以下是一些常见的方法:

方法一:使用防火墙规则

  1. 安装并启用防火墙(如果尚未安装):

    sudo yum install firewalld sudo systemctl start firewalld sudo systemctl enable firewalld 
  2. 允许Jellyfin使用的端口(默认是8096):

    sudo firewall-cmd --permanent --add-port=8096/tcp sudo firewall-cmd --reload 
  3. 限制访问IP: 如果你只想允许特定的IP地址访问Jellyfin,可以使用以下命令:

    sudo firewall-cmd --permanent --add-rich-rule='rule family="ipv4" source address="192.168.1.100" port protocol="tcp" port="8096" accept' sudo firewall-cmd --reload 

方法二:配置HTTP基本认证

  1. 安装Apache HTTP服务器(如果尚未安装):

    sudo yum install httpd sudo systemctl start httpd sudo systemctl enable httpd 
  2. 启用必要的模块

    sudo systemctl enable httpd.service sudo systemctl start httpd.service sudo systemctl status httpd.service sudo systemctl restart httpd.service 
  3. 创建一个密码文件: 使用htpasswd工具创建一个密码文件:

    sudo htpasswd -c /etc/httpd/conf.d/jellyfin.passwd your_username 

    系统会提示你输入并确认密码。

  4. 配置Apache虚拟主机: 编辑Apache配置文件(例如/etc/httpd/conf.d/jellyfin.conf),添加以下内容:

    <VirtualHost *:80> ServerName your_jellyfin_domain_or_ip ProxyPass / http://localhost:8096/ ProxyPassReverse / http://localhost:8096/ <Location /> AuthType Basic AuthName "Restricted Access" AuthUserFile /etc/httpd/conf.d/jellyfin.passwd Require valid-user </Location> </VirtualHost> 
  5. 重启Apache服务器

    sudo systemctl restart httpd 

方法三:使用Nginx作为反向代理

  1. 安装Nginx(如果尚未安装):

    sudo yum install nginx sudo systemctl start nginx sudo systemctl enable nginx 
  2. 配置Nginx: 编辑Nginx配置文件(例如/etc/nginx/conf.d/jellyfin.conf),添加以下内容:

    server { listen 80; server_name your_jellyfin_domain_or_ip; location / { auth_basic "Restricted Access"; auth_basic_user_file /etc/nginx/.htpasswd; proxy_pass http://localhost:8096; 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; } } 
  3. 创建密码文件: 使用htpasswd工具创建一个密码文件:

    sudo htpasswd -c /etc/nginx/.htpasswd your_username 
  4. 重启Nginx服务器

    sudo systemctl restart nginx 

通过以上方法,你可以有效地限制Jellyfin的访问权限,确保只有授权用户才能访问你的媒体服务器。

0