如何在 Ubuntu 20.04 上使用 Nginx 安装 Jellyfin 媒体服务器
在此页
- 先决条件
- 开始
- 安装 Jellyfin
- 将 Nginx 配置为反向代理
- 访问 Jellyfin 网络用户界面
- 使用 Lets Encrypt 保护 Jellyfin
- 结论
Jellyfin 是一种免费的开源媒体流解决方案,可让您托管自己的媒体服务器。它可以安装在 Linux、Windows 和 macOS 上。您可以管理电影、电视节目、音乐和照片等媒体,并使用 Jellyfin 在多个设备上共享它们。它还提供适用于 Android、Android TV 和 Amazon Fire TV 的应用程序。它提供了多种功能,包括支持 DLNA、无播放限制、从 TheTVDB、TheMovieDB 和烂番茄自动获取元数据、自动录制、支持硬件加速等等。
在本教程中,我们将解释如何在 Ubuntu 20.04 上使用 Jellyfin 安装和设置媒体服务器。
先决条件
- 一台运行 Ubuntu 20.04 的服务器。
- 用您的服务器 IP 指向的有效域名。
- 为服务器配置了根密码。
入门
在开始之前,使用以下命令更新您的系统包:
apt-get update -y
更新所有包后,使用以下命令安装其他所需的依赖项:
apt-get install apt-transport-https ca-certificates gnupg2 -y
安装所有依赖项后,您可以继续下一步。
安装 Jellyfin
默认情况下,Jellyfin 包在 Ubuntu 20.04 默认存储库中不可用。因此,您需要将 Jellyfin 存储库添加到您的系统中。首先,使用以下命令下载并添加 GPG 密钥:
wget -O - https://repo.jellyfin.org/jellyfin_team.gpg.key | apt-key add -
添加 GPG 密钥后,使用以下命令将 Jellyfin 存储库添加到 APT:
echo "deb [arch=$( dpkg --print-architecture )] https://repo.jellyfin.org/ubuntu focal main" | tee /etc/apt/sources.list.d/jellyfin.list
接下来,更新存储库缓存并使用以下命令安装 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 Sun 2020-12-27 06:15:40 UTC; 58s ago
Main PID: 8454 (jellyfin)
Tasks: 16 (limit: 4691)
Memory: 92.3M
CGroup: /system.slice/jellyfin.service
??8454 /usr/bin/jellyfin --webdir=/usr/share/jellyfin/web --restartpath=/usr/lib/jellyfin/restart.sh --ffmpeg=/usr/lib/jellyfin-f>
Dec 27 06:15:48 ubunt4 jellyfin[8454]: [06:15:48] [INF] Registering publisher for urn:schemas-upnp-org:device:MediaServer:1 on 104.245.33.>
Dec 27 06:15:48 ubunt4 jellyfin[8454]: [06:15:48] [INF] Executed all pre-startup entry points in 0:00:00.6715621
Dec 27 06:15:48 ubunt4 jellyfin[8454]: [06:15:48] [INF] Core startup complete
Dec 27 06:15:48 ubunt4 jellyfin[8454]: [06:15:48] [INF] Executed all post-startup entry points in 0:00:00.3885698
Dec 27 06:15:48 ubunt4 jellyfin[8454]: [06:15:48] [INF] Startup complete 0:00:08.0109863
Dec 27 06:15:50 ubunt4 jellyfin[8454]: [06:15:50] [INF] StartupTrigger fired for task: Update Plugins
Dec 27 06:15:50 ubunt4 jellyfin[8454]: [06:15:50] [INF] Queueing task PluginUpdateTask
Dec 27 06:15:50 ubunt4 jellyfin[8454]: [06:15:50] [INF] Executing Update Plugins
Dec 27 06:15:50 ubunt4 jellyfin[8454]: [06:15:50] [INF] Update Plugins Completed after 0 minute(s) and 0 seconds
Dec 27 06:15:51 ubunt4 jellyfin[8454]: [06:15:51] [INF] ExecuteQueuedTasks
默认情况下,Jellyfin 监听 8096 端口。您可以使用以下命令验证它:
ss -antpl | grep 8096
您应该得到以下输出:
LISTEN 0 512 *:8096 *:* users:(("jellyfin",pid=8454,fd=285))
此时,Jellyfin 已安装并运行。您现在可以继续下一步。
配置 Nginx 作为反向代理
接下来推荐配置Nginx作为Jellyfin的反向代理。为此,首先,使用以下命令安装 Nginx Web 服务器:
apt-get install nginx -y
安装 Nginx 后,创建一个新的 Nginx 虚拟主机配置文件:
nano /etc/nginx/conf.d/jellyfin.conf
添加以下行:
server {
listen 80;
server_name jellyfin.yourdomain.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 restart nginx
您还可以使用以下命令验证 Nginx 的状态:
systemctl status nginx
您应该看到以下输出:
? nginx.service - A high performance web server and a reverse proxy server
Loaded: loaded (/lib/systemd/system/nginx.service; enabled; vendor preset: enabled)
Active: active (running) since Sun 2020-12-27 06:18:13 UTC; 6s ago
Docs: man:nginx(8)
Process: 9865 ExecStartPre=/usr/sbin/nginx -t -q -g daemon on; master_process on; (code=exited, status=0/SUCCESS)
Process: 9879 ExecStart=/usr/sbin/nginx -g daemon on; master_process on; (code=exited, status=0/SUCCESS)
Main PID: 9883 (nginx)
Tasks: 3 (limit: 4691)
Memory: 3.6M
CGroup: /system.slice/nginx.service
??9883 nginx: master process /usr/sbin/nginx -g daemon on; master_process on;
??9884 nginx: worker process
??9885 nginx: worker process
Dec 27 06:18:13 ubunt4 systemd[1]: Starting A high performance web server and a reverse proxy server...
Dec 27 06:18:13 ubunt4 systemd[1]: Started A high performance web server and a reverse proxy server.
此时,Nginx 已安装并配置为服务于 Jellyfin。您现在可以继续下一步。
访问 Jellyfin Web UI
现在,打开您的 Web 浏览器并使用 URL http://jellyfin.yourdomain.com 访问 Jellyfin Web UI。您将被重定向到以下屏幕:

选择您的语言,然后单击“下一步”按钮。您应该看到以下屏幕:

提供您的管理员用户名和密码,然后单击“下一步”按钮。您应该看到以下屏幕:

单击下一步按钮。您应该看到以下屏幕:

选择您的元数据语言和国家/地区,然后单击下一步按钮。您应该看到以下屏幕:

选择所需的选项,然后单击“下一步”按钮。您应该看到以下屏幕:

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

提供您的用户名、密码,然后单击“登录”按钮。您应该在以下屏幕中看到 Jellyfin 仪表板:

您现在可以将媒体添加到媒体库并通过 Internet 访问它。
使用 Lets Encrypt 保护 Jellyfin
接下来,您需要安装 Certbot 客户端包来安装管理 Lets Encrypt SSL。首先,使用以下命令安装 Certbot:
apt-get install python3-certbot-nginx -y
安装完成后,运行以下命令在您的网站上安装 Lets Encrypt SSL:
certbot --nginx -d jellyfin.yourdomain.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):
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
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.yourdomain.com
Waiting for verification...
Cleaning up challenges
Deploying Certificate to VirtualHost /etc/nginx/sites-enabled/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/sites-enabled/jellyfin.conf
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Congratulations! You have successfully enabled https://jellyfin.yourdomain.com
You should test your configuration at:
https://www.ssllabs.com/ssltest/analyze.html?d=jellyfin.yourdomain.com
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
IMPORTANT NOTES:
- Congratulations! Your certificate and chain have been saved at:
/etc/letsencrypt/live/jellyfin.yourdomain.com/fullchain.pem
Your key file has been saved at:
/etc/letsencrypt/live/jellyfin.yourdomain.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.
现在,您的网站已通过 Lets Encrypt SSL 得到保护。您可以使用 URL https://jellyfin.yourdomain.com 安全地访问它。
结论
恭喜!您已经在 Ubuntu 20.04 服务器上成功安装并配置了带有 Nginx 和 Lets Encrypt SSL 的 Jellyfin。您现在可以流式传输您的媒体并从 Web 浏览器或使用 Jellyfin 应用程序访问它。如果您有任何问题,请随时问我。