[Debian]Jellyfin 公网个人媒体中心的搭建教程(更新于:20240219)

上次写 NAS 选购指南的时候,突然想起我还没有写过个人媒体中心这方面的教程,考虑到很多人的 NAS 都有这方面的用途,所以想了下还是写篇 Jellyfin 的搭建教程吧。当然,我知道能搭建媒体中心的程序不止 Jellyfin 这一个,Plex Emby 用的人也是挺多的,但是我个人还是更喜欢优先使用开源免费的产品,所以这里就只说 Jellyfin 了。

一、前期准备

先说下本教程的系统环境和配置吧!

系统:Debian 11(bullseye)

Web 服务器:Nginx 1.18.0

Jellyfin 版本:10.7.7

对了再说下 Jellyfin 官网https://jellyfin.org

因为 Jellyfin 不需要额外再安装数据库之类的东西,所以这次我也没有使用 LNMP 一键脚本来安装环境,只是使用了 Debian 自带源里的 Nginx。如果各位对 Web 服务器有要求的话,也可以自己选择安装 Apache 或者别的之类的来代替 Nginx,我自己是更喜欢 Nginx 一些,所以本文就只写 Nginx 相关的东西了。

二、必要程序安装

前期需要安装的东西不多,基本上安装好 Nginx 就完事了,所以我就直接贴命令吧,在 VPS 命令行里输入即可。

apt install nginx curl apt-transport-https gnupg sudo

解释下除了 Nginx 后面安装的两个包,curl 大多就是用来下载东西的,大多系统都自带了,不一定要自己安装,apt-transport-https 是让 apt 能够使用 https 的,这个不用了解太多,只是为了能正常使用 jellyfin 的软件源而装的。最后安装了个 sudo 是因为后面的命令会用到,实际上如果你是 root 用户可以不安装并把后面命令带有 sudo 的字样删了就行。_(:з)∠)_

三、正式安装

注意,由于 Jellyfin 官方的教程有所更改(我也是才发现的),所以我在20240219修改了下面的部分内容,匹配官方的手动安装教程。对于 Debian 系的发行版来说,官方现在有提供方便好用的一键安装教程,如果你不想自己一步步操作的话,直接执行下面的命令就可直接安装 Jellyfin 了。

一键脚本安装命令如下:

curl https://repo.jellyfin.org/install-debuntu.sh | sudo bash

如果你还是喜欢自己手动安装 Jellyfin,可以再看下面的教程。

Jellyfin 手动安装

手动安装分为两步,我们先要把 Jellyfin 源的密钥加到系统里:

sudo mkdir -p /etc/apt/keyrings
curl -fsSL https://repo.jellyfin.org/jellyfin_team.gpg.key | sudo gpg --dearmor -o /etc/apt/keyrings/jellyfin.gpg

等密钥加好了,我们接着添加 Jellyfin 的安装源到系统里:

export VERSION_OS="$( awk -F'=' '/^ID=/{ print $NF }' /etc/os-release )"
export VERSION_CODENAME="$( awk -F'=' '/^VERSION_CODENAME=/{ print $NF }' /etc/os-release )"
export DPKG_ARCHITECTURE="$( dpkg --print-architecture )"
cat <<EOF | sudo tee /etc/apt/sources.list.d/jellyfin.sources
Types: deb
URIs: https://repo.jellyfin.org/${VERSION_OS}
Suites: ${VERSION_CODENAME}
Components: main
Architectures: ${DPKG_ARCHITECTURE}
Signed-By: /etc/apt/keyrings/jellyfin.gpg
EOF

解释一下上面的命令,首先是根据系统版本导入几个环境变量,然后再根据变量确定安装源文件该怎么写。

VERSION_OS 变量指的是发行版,只支持 Ubuntu 和 Debian,官方说如果不是这两个就选择最接近的。VERSION_CODENAME 变量指的是发型代号。DPKG_ARCHITECTURE 指的是 CPU 架构,目前 Jellyfin 支持 amd64|armhf|arm64 这三个,特别指出不支持 i386 也就是说没法在 32 位系统里安装。

PS:上面的只是解释,我们不需要实际去写这些变量,直接照着命令敲就行了,会自己确认,解释只是以防万一如果无法自动识别的话好自己写。

上面的都做完之后,就可以安装 Jellyfin 了:

sudo apt update
sudo apt install jellyfin

Jellyfin 安装好之后,还不能马上通过网页访问,需要先给前面安装好的 Web 服务器 Nginx 设置好配置才行。

这里解释一下,Jellyfin 本身是不需要借助 Nginx 来提供服务的,但是如果用公网访问 Jellyfin 的话,不借助 Nginx 使用 Jellyfin 会不太方便,所以我这里才额外写下 Nginx 的配置。

Nginx 配置

使用 apt 安装的 Nginx,其网站默认使用的配置文件目录为/etc/nginx/sites-enabled,只要在这个目录下添加好配置文件,重载下 Nginx 即可让配置文件生效,这里我以创建/etc/nginx/sites-enabled/jellyfin 这个配置文件为例,写下其中要写的配置信息。

cat > /etc/nginx/sites-enabled/jellyfin<<EOF
server {
    listen 80;
    listen [::]:80;
    server_name example.com;

    # Uncomment to redirect HTTP to HTTPS
    return 301 https://$host$request_uri;
}

server {
    listen 443 ssl http2;
    listen [::]:443 ssl http2;
    server_name example.com;

    # use a variable to store the upstream proxy
    # in this example we are using a hostname which is resolved via DNS
    # (if you aren't using DNS remove the resolver line and change the variable to point to an IP address e.g `set $jellyfin 127.0.0.1`)
    set $jellyfin 127.0.0.1;

    ssl_certificate /etc/letsencrypt/live/example.com/fullchain.pem;
    ssl_certificate_key /etc/letsencrypt/live/example.com/privkey.pem;
    #include /etc/letsencrypt/options-ssl-nginx.conf;
    #ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem;
    add_header Strict-Transport-Security "max-age=31536000" always;
    ssl_trusted_certificate /etc/letsencrypt/live/example.com/chain.pem;
    ssl_stapling on;
    ssl_stapling_verify on;

    #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";

    # Content Security Policy
    # See: https://developer.mozilla.org/en-US/docs/Web/HTTP/CSP
    # Enforces https content and restricts JS/CSS to origin
    # External Javascript (such as cast_sender.js for Chromecast) must be whitelisted.
    #add_header Content-Security-Policy "default-src https: data: blob: http://image.tmdb.org; style-src 'self' 'unsafe-inline'; script-src 'self' 'unsafe-inline' https://www.gstatic.com/cv/js/sender/v1/cast_sender.js https://www.youtube.com blob:; worker-src 'self' blob:; connect-src 'self'; object-src 'none'; frame-ancestors 'self'";

    location = / {
        return 302 https://$host/web/;
    }

    location / {
        # Proxy main Jellyfin traffic
        proxy_pass http://$jellyfin: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://$jellyfin: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;
    }
}
EOF

注意,上述命令第一行与最后一行是创建对应配置文件并写入配置信息用的,实际配置信息是中间的部分。

以上配置文件来自官方的示例文档,有更多需求的可以看下官方的示例页面:https://jellyfin.org/docs/general/networking/nginx.html

注意,上面的 Nginx 配置里有几个地方是需要根据自己的情况修改的:

  1. server_name 内的 example.com 要替换成你自己实际使用的域名
  2. set $jellyfin 127.0.0.1; 这一行指定的是 Jellyfin 服务器的 IP,我们一般都是本机所以写的是 127.0.0.1
  3. Nginx 配置文件里开启了 443 端口,也就是开启了 HTTPS,其中的 SSL 证书部分需要根据自己情况修改
  4. 所有配置信息里 proxy_pass http://$jellyfin:8096 这部分里的 8096 要改成 Jellyfin 实际监听的端口。没动过 Jellyfin 默认就是 8096,不需要再改动

OK,差不多就是这些注意事项,对于新手来说可能稍显麻烦的是配置 SSL 证书这部分,因为这个要你自己先去申请好 SSL 证书才行。本来的话,我是想把申请证书的部分也写在教程里的,不过想了想每个人的证书获得方式都不一定相同,我写了也也不一定适用所有人,所以想想还是算了,大家自己记得注意一下。

上面的配置写好保存之后,重载下 Nginx 使配置文件生效:

nginx -s reload

四、后续配置

前面把 Jellyfin 安装好了,Nginx 也配置好了,剩下的就是别忘了把域名和 VPS IP 绑定好了,这个跟普通网站一样,就不多说了。我这里主要是想补充一点,因为本篇文章主要说的是搭建 Jellyfin 这方面,没有针对后续的媒体库配置,插件安装这些进行说明(主要是每个人的使用习惯都不一样),所以我个人建议想用 Jellyfin 的朋友在搭建好之后,还是多看下官方给的文档说明:https://jellyfin.org/docs/general/quick-start.html 虽然官方写的东西不多,不过要是想好好使用 Jellyfin 的话还是多看下比较好,我个人觉得里面关于文件命名,转码这些都是很有必要看的。

结束

OK!水完一篇文了233333

本来我以为 Jellyfin 的教程我会写挺多的,结果写完才发现我真正要说的不多,因为官方都把命令给你写好了,你只用在命令行里照着输入就能安装好,而且 Jellyfin 也不像博客一样还得配置数据库什么的,安装好之后就能上手使用,所以我要写的东西真的不多……

Jellyfin 的搭建教程就写这么多了,其实如果不是公网搭建的话,自己在本地搭建还要更简单一些,因为不需要再额外安装 Nginx 就能很方便的使用。另外我提醒下大家,因为 Jellyfin 有个转码的问题,开启之后可能会对 VPS 产生不小的压力,如果有这方面需求的记得提前考虑下自己的 VPS 配置够不够用。

好了不说了,以后有机会我看看能不能写下 Jellyfin 具体的一些配置方面的教程吧,这个应该会更有用一些,各位回见~

PS:文章的特色图片是截图的官方 demo 网站界面,想体验 Jellyfin 的可以先去看下官方的 demo 演示站点:https://demo.jellyfin.org/stable

文章标题:[Debian]Jellyfin 公网个人媒体中心的搭建教程(更新于:20240219)
本文作者:希卡米
链接:https://hikami.moe/master/program/3986.html

如非文内特别说明,博客内作品均默认采用知识共享署名-非商业性使用-相同方式共享 4.0 国际许可协议进行许可。
知识共享许可协议
暂无评论

发送评论 编辑评论

|´・ω・)ノ
ヾ(≧∇≦*)ゝ
(☆ω☆)
(╯‵□′)╯︵┴─┴
 ̄﹃ ̄
(/ω\)
∠( ᐛ 」∠)_
(๑•̀ㅁ•́ฅ)
→_→
୧(๑•̀⌄•́๑)૭
٩(ˊᗜˋ*)و
(ノ°ο°)ノ
(´இ皿இ`)
⌇●﹏●⌇
(ฅ´ω`ฅ)
(╯°A°)╯︵○○○
φ( ̄∇ ̄o)
ヾ(´・ ・`。)ノ"
( ง ᵒ̌皿ᵒ̌)ง⁼³₌₃
(ó﹏ò。)
Σ(っ °Д °;)っ
( ,,´・ω・)ノ"(´っω・`。)
╮(╯▽╰)╭
o(*////▽////*)q
>﹏<
( ๑´•ω•) "(ㆆᴗㆆ)
😂
😀
😅
😊
🙂
🙃
😌
😍
😘
😜
😝
😏
😒
🙄
😳
😡
😔
😫
😱
😭
💩
👻
🙌
🖕
👍
👫
👬
👭
🌚
🌝
🙈
💊
😶
🙏
🍦
🍉
😣
Source: github.com/k4yt3x/flowerhd
颜文字
Emoji
小恐龙
花!
上一篇
下一篇