Jellyfin 媒体服务器搭建教程 + 配置meilisearch搜索后端

分享讨论IT相关的内容
回复
头像
BobMaster
锋芒初露
锋芒初露
帖子: 1362
注册时间: 2020年 12月 7日 08:05
来自: 神秘的东方
我的状态: 🎯
为圈友点赞: 438 次
被圈友点赞: 288 次
联系:

Jellyfin 媒体服务器搭建教程 + 配置meilisearch搜索后端

帖子 BobMaster »

Jellyfin 是一个开源的家庭媒体服务器,可以在线观看影视、听音乐等。
除浏览器Web端之外,还有各种开源免费的客户端,包括但不限于Android、Android TV、iOS、tvOS、Windows、macOS、Linux等。

搜索服务我们使用JellySearch代替Jellyfin自带的搜索后端。

为了方便,我们采用docker部署相关服务,compose.yaml配置文件如下:

代码: 全选

services:
  jellyfin:
    image: lscr.io/linuxserver/jellyfin:latest
    container_name: jellyfin
    environment:
      - PUID=33
      - PGID=33
      - TZ=Asia/Shanghai
    volumes:
      - ./library:/config
      - ./fonts:/usr/share/fonts
    #  - /mnt/media-server/jellyfin:/data
    ports:
      - 127.0.0.1:8096:8096
    restart: unless-stopped

  jellysearch:
    image: domistyle/jellysearch
    restart: unless-stopped
    depends_on:
      - jellyfin
      - meilisearch
    ports:
      - 127.0.0.1:5000:5000
    volumes:
      - ./library:/config:ro
    environment:
      JELLYFIN_URL: "http://jellyfin:8096"
      JELLYFIN_CONFIG_DIR: "/config/data"
      MEILI_MASTER_KEY: "quanquanspace"
      INDEX_CRON: "0 0 0/2 ? * * *"
    
  meilisearch:
    image: getmeili/meilisearch:v1.9
    restart: unless-stopped
    volumes:
      - ./meilisearch:/meili_data
    environment:
      MEILI_MASTER_KEY: "quanquanspace"

这里的PUID=33PGID=33指定的是jellyfin运行的用户,如果去掉则是以root运行,这里33通过命令 id www-data 得出。

接着docker compose up -d运行服务,下面配置一下Nginx反向代理,创建一个配置文件 /etc/nginx/conf.d/jellyfin.conf
你需要根据实际情况相应修改一下server_name,ssl证书的路径

代码: 全选

proxy_cache_path  /var/cache/nginx/jellyfin-videos levels=1:2 keys_zone=jellyfin-videos:100m inactive=90d max_size=3g;
proxy_cache_path /var/cache/nginx/jellyfin levels=1:2 keys_zone=jellyfin:100m max_size=3g inactive=30d use_temp_path=off;

map $request_uri $h264Level { ~(h264-level=)(.+?)& $2; }
map $request_uri $h264Profile { ~(h264-profile=)(.+?)& $2; }

server {
    listen 80;
    listen [::]:80;
    server_name jellyfin.quanquan.space;

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

server {
    listen 443 ssl http2;
    listen [::]:443 ssl http2;
    server_name jellyfin.quanquan.space;

    ## The default `client_max_body_size` is 1M, this might not be enough for some posters, etc.
    client_max_body_size 20M;

    ssl_certificate /etc/nginx/certs/jellyfin.quanquan.space.cert.pem;
    ssl_certificate_key /etc/nginx/certs/jellyfin.quanquan.space.key.pem;
    ssl_session_timeout 1d;
    ssl_session_cache shared:MozSSL:10m;  # about 40000 sessions
    ssl_session_tickets off;
    
    # intermediate configuration
    ssl_protocols TLSv1.2 TLSv1.3;
    ssl_ciphers ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:DHE-RSA-AES128-GCM-SHA256:DHE-RSA-AES256-GCM-SHA384:DHE-RSA-CHACHA20-POLY1305;
    ssl_prefer_server_ciphers on;


    # Security / XSS Mitigation Headers
    # NOTE: X-Frame-Options may cause issues with the webOS app
    add_header X-Frame-Options "SAMEORIGIN";
    add_header X-Content-Type-Options "nosniff";

    # COOP/COEP. Disable if you use external plugins/images/assets
    add_header Cross-Origin-Opener-Policy "same-origin" always;
    add_header Cross-Origin-Embedder-Policy "require-corp" always;
    add_header Cross-Origin-Resource-Policy "same-origin" always;

    # Permissions policy. May cause issues on some clients
    add_header Permissions-Policy "accelerometer=(), ambient-light-sensor=(), battery=(), bluetooth=(), camera=(), clipboard-read=(), display-capture=(), document-domain=(), encrypted-media=(), gamepad=(), geolocation=(), gyroscope=(), hid=(), idle-detection=(), interest-cohort=(), keyboard-map=(), local-fonts=(), magnetometer=(), microphone=(), payment=(), publickey-credentials-get=(), serial=(), sync-xhr=(), usb=(), xr-spatial-tracking=()" always;


    # 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.
    # NOTE: The default CSP headers may cause issues with the webOS app
    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 https://www.youtube.com blob:; worker-src 'self' blob:; connect-src 'self'; object-src 'none'; frame-ancestors 'self'";

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

    location / {
        # Proxy JellySearch
        if ($arg_searchTerm) {
            proxy_pass http://127.0.0.1:5000;
            break;
        }

        # Proxy main Jellyfin traffic
        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 /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;
    }

    # Set in Server block
    location ~* ^/Videos/(.*)/(?!live)
    {
    # Set size of a slice (this amount will be always requested from the backend by nginx)
    # Higher value means more latency, lower more overhead
    # This size is independent of the size clients/browsers can request
    slice 2m;

    proxy_cache jellyfin-videos;
    proxy_cache_valid 200 206 301 302 30d;
    proxy_ignore_headers Expires Cache-Control Set-Cookie X-Accel-Expires;
    proxy_cache_use_stale error timeout invalid_header updating http_500 http_502 http_503 http_504;
    proxy_connect_timeout 15s;
    proxy_http_version 1.1;
    proxy_set_header Connection "";
    # Transmit slice range to the backend
    proxy_set_header Range $slice_range;

    # This saves bandwidth between the proxy and jellyfin, as a file is only downloaded one time instead of multiple times when multiple clients want to at the same time
    # The first client will trigger the download, the other clients will have to wait until the slice is cached
    # Esp. practical during SyncPlay
    proxy_cache_lock on;
    proxy_cache_lock_age 60s;

    proxy_pass http://127.0.0.1:8096;
    proxy_cache_key "jellyvideo$uri?MediaSourceId=$arg_MediaSourceId&VideoCodec=$arg_VideoCodec&AudioCodec=$arg_AudioCodec&AudioStreamIndex=$arg_AudioStreamIndex&VideoBitrate=$arg_VideoBitrate&AudioBitrate=$arg_AudioBitrate&SubtitleMethod=$arg_SubtitleMethod&TranscodingMaxAudioChannels=$arg_TranscodingMaxAudioChannels&RequireAvc=$arg_RequireAvc&SegmentContainer=$arg_SegmentContainer&MinSegments=$arg_MinSegments&BreakOnNonKeyFrames=$arg_BreakOnNonKeyFrames&h264-profile=$h264Profile&h264-level=$h264Level&slicerange=$slice_range";

    # add_header X-Cache-Status $upstream_cache_status; # This is only for debugging cache

    }


    # Cache images (inside server block)
    location ~ /Items/(.*)/Images {
    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;

    proxy_cache jellyfin;
    proxy_cache_revalidate on;
    proxy_cache_lock on;
    # add_header X-Cache-Status $upstream_cache_status; # This is only to check if cache is working
    }
}
nginx -t测试一下配置,没问题就重载一下Nginx,nginx -s reload

然后浏览器访问 https://你的域名 ,创建用户,配置媒体资源即可。
图片
人生如音乐,欢乐且自由
回复

在线用户

正浏览此版面之用户: Google [Bot] 和 1 访客