本教程适用于以下操作系统版本

  • Debian 12 (Bookworm)
  • Debian 11 (Bullseye)
  • Debian 10 (Buster)

在此页面上

  • 先决条件
  • 开始使用
  • 安装 Jellyfin
  • 将 Nginx 配置为反向代理
  • 访问 Jellyfin
  • 使用 Let's Encrypt SSL 保护 Jellyfin
  • 结论

Jellyfin 是一个开源媒体流系统,可让您管理和流式传输您的媒体。它是跨平台的,可替代 Emby 和 Plex 等其他应用程序。使用 Jellyfin,您可以从基于 Web 的界面组织和共享您的媒体文件、电视节目、音乐和照片。您可以通过互联网在 PC、平板电脑、手机、Roku 和电视上访问这些流式传输的媒体。Jellyfin 会自动从 TheMovieDB、OpenMovie、Rotten Tomatoes 和 TheTVDB 数据库获取元数据。

在这篇文章中,我们将向您展示如何在 Debian 10 上安装 Jellyfin 媒体流服务器,并将 Nginx 作为反向代理。

先决条件

  • 一台运行 Debian 10 的服务器。
  • 一个指向您服务器 IP 的有效域名。
  • 服务器上配置了 root 密码。

开始使用

首先,您需要将系统软件包更新到最新版本。您可以使用以下命令更新它们:

apt-get update -y

所有软件包更新完成后,使用以下命令安装其他所需的软件包:

apt-get install apt-transport-https ca-certificates gnupg2 curl git -y

所有软件包安装完成后,您可以继续下一步。

安装 Jellyfin

默认情况下,Debian 10 软件仓库中不包含 Jellyfin 软件包。因此您需要将 Jellyfin 软件仓库添加到您的 APT 中。

您可以使用以下命令添加它:

echo "deb [arch=$( dpkg --print-architecture )] https://repo.jellyfin.org/debian buster main" | tee /etc/apt/sources.list.d/jellyfin.list

添加软件仓库后,使用以下命令添加 GPG 密钥:

wget -O - https://repo.jellyfin.org/jellyfin_team.gpg.key | apt-key add -

接下来,使用以下命令更新软件仓库并安装 Jellyfin:

apt-get update -y
apt-get install jellyfin -y

Jellyfin 安装完成后,您可以使用以下命令检查 Jellyfin 的状态:

systemctl status jellyfin

您应该会看到以下输出:

? jellyfin.service - Jellyfin Media Server
   Loaded: loaded (/lib/systemd/system/jellyfin.service; enabled; vendor preset: enabled)
  Drop-In: /etc/systemd/system/jellyfin.service.d
           ??jellyfin.service.conf
   Active: active (running) since Mon 2021-03-22 08:27:42 UTC; 5min ago
 Main PID: 10192 (jellyfin)
    Tasks: 17 (limit: 4701)
   Memory: 113.9M
   CGroup: /system.slice/jellyfin.service
           ??10192 /usr/bin/jellyfin --webdir=/usr/share/jellyfin/web --restartpath=/usr/lib/jellyfin/restart.sh --ffmpeg=/usr/lib/jellyfin-ffm

Mar 22 08:27:45 debian10 jellyfin[10192]: [08:27:45] [WRN] 127.0.0.1/32: GetBindInterface: Loopback 127.0.0.1 returned.
Mar 22 08:27:45 debian10 jellyfin[10192]: [08:27:45] [INF] Executed all pre-startup entry points in 0:00:00.1545678
Mar 22 08:27:45 debian10 jellyfin[10192]: [08:27:45] [INF] Core startup complete
Mar 22 08:27:46 debian10 jellyfin[10192]: [08:27:46] [INF] Executed all post-startup entry points in 0:00:00.1976994
Mar 22 08:27:46 debian10 jellyfin[10192]: [08:27:46] [INF] Startup complete 0:00:03.6985068
Mar 22 08:27:48 debian10 jellyfin[10192]: [08:27:48] [INF] StartupTrigger fired for task: Update Plugins
Mar 22 08:27:48 debian10 jellyfin[10192]: [08:27:48] [INF] Queuing task PluginUpdateTask
Mar 22 08:27:48 debian10 jellyfin[10192]: [08:27:48] [INF] Executing Update Plugins
Mar 22 08:27:49 debian10 jellyfin[10192]: [08:27:49] [INF] Update Plugins Completed after 0 minute(s) and 0 seconds
Mar 22 08:27:49 debian10 jellyfin[10192]: [08:27:49] [INF] ExecuteQueuedTasks

此时,Jellyfin 已启动并正在监听 8096 端口。您可以使用以下命令检查它:

ss -antpl | grep 8096

输出:

LISTEN    0         128                0.0.0.0:8096             0.0.0.0:*        users:(("jellyfin",pid=10192,fd=289))                                          

将 Nginx 配置为反向代理

接下来,您需要将 Nginx 配置为反向代理,以便通过 80 端口访问 Jellyfin。

首先,使用以下命令安装 Nginx 软件包:

apt-get install nginx -y

安装完成后,使用以下命令创建一个新的 Nginx 配置文件:

nano /etc/nginx/conf.d/jellyfin.conf

添加以下行:

server {
      listen 80;
      server_name jellyfin.example.com;

      access_log /var/log/nginx/jellyfin.access;
      error_log /var/log/nginx/jellyfin.error;

      set $jellyfin 127.0.0.1;

      location / {
          proxy_pass http://127.0.0.1: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;
          proxy_set_header X-Forwarded-Protocol $scheme;
          proxy_set_header X-Forwarded-Host $http_host;

          # Disable buffering when the nginx proxy gets very resource heavy upon streaming
          proxy_buffering off;
      }

      # location block for /web - This is purely for aesthetics so /web/#!/ works instead of having to go to /web/index.html/#!/
      location ~ ^/web/$ {
          # Proxy main Jellyfin traffic
          proxy_pass http://$jellyfin:8096/web/index.html/;
          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;
          proxy_set_header X-Forwarded-Protocol $scheme;
          proxy_set_header X-Forwarded-Host $http_host;
      }

      location /socket {
          # Proxy Jellyfin Websockets traffic
          proxy_pass http://$127.0.0.1:8096;
          proxy_http_version 1.1;
          proxy_set_header Upgrade $http_upgrade;
          proxy_set_header Connection "upgrade";
          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;
          proxy_set_header X-Forwarded-Protocol $scheme;
          proxy_set_header X-Forwarded-Host $http_host;
      }

        # Security / XSS Mitigation Headers
        add_header X-Frame-Options "SAMEORIGIN";
        add_header X-XSS-Protection "1; mode=block";
        add_header X-Content-Type-Options "nosniff";
}

保存并关闭文件,然后使用以下命令验证 Nginx 是否存在任何语法错误:

nginx -t

输出:

nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful

接下来,重启 Nginx 服务以应用更改:

systemctl reload nginx

访问 Jellyfin

现在,打开您的 Web 浏览器,使用 URL http://jellyfin.example.com 访问 Jellyfin Web 界面。您将被重定向到以下页面:

如何在 Debian 10 上安装 Jellyfin 媒体服务器的完整教程

选择您的语言并单击 Next 按钮。您应该会看到以下页面:

如何在 Debian 10 上安装 Jellyfin 媒体服务器的完整教程

提供您的用户名和密码,然后单击 Next 按钮。您应该会看到以下页面:

如何在 Debian 10 上安装 Jellyfin 媒体服务器的完整教程

单击 Next 按钮。您应该会看到以下页面:

如何在 Debian 10 上安装 Jellyfin 媒体服务器的完整教程

选择您的元数据语言并单击 Next 按钮。您应该会看到以下页面:

如何在 Debian 10 上安装 Jellyfin 媒体服务器的完整教程

允许远程访问并单击 Next 按钮。安装完成后,您应该会看到以下页面:

如何在 Debian 10 上安装 Jellyfin 媒体服务器的完整教程

单击 Finish 按钮完成安装。您应该会看到 Jellyfin 登录页面:

如何在 Debian 10 上安装 Jellyfin 媒体服务器的完整教程

提供您的用户名和密码,然后单击 Sign In 按钮。您应该会在以下页面中看到 Jellyfin 仪表板:

如何在 Debian 10 上安装 Jellyfin 媒体服务器的完整教程

使用 Let's Encrypt SSL 保护 Jellyfin

接下来,您需要安装 Certbot 客户端软件包,以安装和管理 Let's Encrypt SSL。首先,使用以下命令安装 Certbot:

apt-get install python3-certbot-nginx -y

安装完成后,运行以下命令在您的网站上安装 Let's Encrypt SSL:

certbot --nginx -d jellyfin.example.com

系统会要求您提供有效的电子邮件地址并接受服务条款,如下所示:

Saving debug log to /var/log/letsencrypt/letsencrypt.log
Plugins selected: Authenticator nginx, Installer nginx
Enter email address (used for urgent renewal and security notices) (Enter 'c' to
cancel): 
[email protected]


- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Please read the Terms of Service at
https://letsencrypt.org/documents/LE-SA-v1.2-November-15-2017.pdf. You must
agree in order to register with the ACME server at
https://acme-v02.api.letsencrypt.org/directory
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
(A)gree/(C)ancel: A

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Would you be willing to share your email address with the Electronic Frontier
Foundation, a founding partner of the Let's Encrypt project and the non-profit
organization that develops Certbot? We'd like to send you email about our work
encrypting the web, EFF news, campaigns, and ways to support digital freedom.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
(Y)es/(N)o: Y
Obtaining a new certificate
Performing the following challenges:
http-01 challenge for jellyfin.example.com
Waiting for verification...
Cleaning up challenges
Deploying Certificate to VirtualHost /etc/nginx/conf.d/jellyfin.conf

接下来,选择是否将 HTTP 流量重定向到 HTTPS,如下所示:

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
1: No redirect - Make no further changes to the webserver configuration.
2: Redirect - Make all requests redirect to secure HTTPS access. Choose this for
new sites, or if you're confident your site works on HTTPS. You can undo this
change by editing your web server's configuration.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Select the appropriate number [1-2] then [enter] (press 'c' to cancel): 2

输入 2 并按 Enter 键完成安装。您应该会看到以下输出:

Redirecting all traffic on port 80 to ssl in /etc/nginx/conf.d/jellyfin.conf

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Congratulations! You have successfully enabled https://jellyfin.example.com

You should test your configuration at:
https://www.ssllabs.com/ssltest/analyze.html?d=jellyfin.example.com
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

IMPORTANT NOTES:
 - Congratulations! Your certificate and chain have been saved at:
   /etc/letsencrypt/live/jellyfin.example.com/fullchain.pem
   Your key file has been saved at:
   /etc/letsencrypt/live/jellyfin.example.com/privkey.pem
   Your cert will expire on 2020-10-30. To obtain a new or tweaked
   version of this certificate in the future, simply run certbot again
   with the "certonly" option. To non-interactively renew *all* of
   your certificates, run "certbot renew"
 - Your account credentials have been saved in your Certbot
   configuration directory at /etc/letsencrypt. You should make a
   secure backup of this folder now. This configuration directory will
   also contain certificates and private keys obtained by Certbot so
   making regular backups of this folder is ideal.
 - If you like Certbot, please consider supporting our work by:

   Donating to ISRG / Let's Encrypt:   https://letsencrypt.org/donate
   Donating to EFF:                    https://eff.org/donate-le

 - We were unable to subscribe you the EFF mailing list because your
   e-mail address appears to be invalid. You can try again later by
   visiting https://act.eff.org.

现在,您的网站已使用 Let's Encrypt SSL 进行保护。您可以使用 URL https://jellyfin.example.com 安全地访问它。

结论

恭喜!您已在 Debian 10 服务器上成功安装 Jellyfin。现在您可以轻松地与朋友、家人和其他用户共享您的媒体。