Ricerca nel sito web

Come installare Jellyfin Media Server con Nginx su Ubuntu 20.04


Su questa pagina

  1. Prerequisiti
  2. Per iniziare
  3. Installa Jellyfin
  4. Configura Nginx come proxy inverso
  5. Accedi all'interfaccia utente web di Jellyfin
  6. Proteggi Jellyfin con Lets Encrypt
  7. Conclusione

Jellyfin è una soluzione di streaming multimediale gratuita e open source che ti consente di ospitare il tuo server multimediale. Può essere installato su Linux, Windows e macOS. Puoi gestire i tuoi contenuti multimediali come film, programmi TV, musica e foto e condividerli su più dispositivi utilizzando Jellyfin. Fornisce anche applicazioni per Android, Android TV e Amazon Fire TV. Offre diverse funzionalità tra cui, Supporta DLNA, Nessun limite di riproduzione, Recupera automaticamente i metadati da TheTVDB, TheMovieDB e Rotten Tomatoes, Registrazioni automatiche, Supporta l'accelerazione hardware e molti altri.

In questo tutorial, spiegheremo come installare e configurare un media server con Jellyfin su Ubuntu 20.04.

Prerequisiti

  • Un server che esegue Ubuntu 20.04.
  • Un nome di dominio valido indicato con l'IP del tuo server.
  • Il server è configurato con una password di root.

Iniziare

Prima di iniziare, aggiorna i pacchetti di sistema utilizzando il seguente comando:

apt-get update -y

Una volta aggiornati tutti i pacchetti, installa le altre dipendenze richieste con il seguente comando:

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

Dopo aver installato tutte le dipendenze, puoi procedere al passaggio successivo.

Installa Jellyfin

Per impostazione predefinita, il pacchetto Jellyfin non è disponibile nel repository predefinito di Ubuntu 20.04. Quindi dovrai aggiungere il repository Jellyfin al tuo sistema. Innanzitutto, scarica e aggiungi la chiave GPG con il seguente comando:

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

Una volta aggiunta la chiave GPG, aggiungi il repository Jellyfin all'APT con il seguente comando:

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

Successivamente, aggiorna la cache del repository e installa Jellyfin con il seguente comando:

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

Dopo aver installato Jellyfin, puoi verificare lo stato del servizio Jellyfin con il seguente comando:

systemctl status jellyfin

Dovresti ottenere il seguente output:

? 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

Per impostazione predefinita, Jellyfin è in ascolto sulla porta 8096. Puoi verificarlo con il seguente comando:

ss -antpl | grep 8096

Dovresti ottenere il seguente output:

LISTEN    0         512                      *:8096                   *:*        users:(("jellyfin",pid=8454,fd=285))                                           

A questo punto, Jellyfin è installato e funzionante. Ora puoi procedere al passaggio successivo.

Configura Nginx come proxy inverso

Successivamente, si consiglia di configurare Nginx come proxy inverso per Jellyfin. Per fare ciò, prima installa il server web Nginx con il seguente comando:

apt-get install nginx -y

Una volta installato Nginx, crea un nuovo file di configurazione dell'host virtuale Nginx:

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

Aggiungi le seguenti righe:

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

}

Salva e chiudi il file quando hai finito. Quindi, verifica Nginx per qualsiasi errore di sintassi con il seguente comando:

nginx -t

Se tutto va bene, dovresti ottenere il seguente output:

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

Successivamente, riavvia il servizio Nginx per applicare le modifiche alla configurazione:

systemctl restart nginx

Puoi anche verificare lo stato di Nginx con il seguente comando:

systemctl status nginx

Dovresti vedere il seguente output:

? 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.

A questo punto, Nginx è installato e configurato per servire Jellyfin. Ora puoi procedere al passaggio successivo.

Accedi all'interfaccia utente Web di Jellyfin

Ora, apri il tuo browser web e accedi all'interfaccia utente web di Jellyfin utilizzando l'URL http://jellyfin.yourdomain.com. Verrai reindirizzato alla seguente schermata:

Seleziona la tua lingua e fai clic sul pulsante Avanti. Dovresti vedere la seguente schermata:

Fornire il nome utente e la password dell'amministratore e fare clic sul pulsante Avanti. Dovresti vedere la seguente schermata:

Fare clic sul pulsante Avanti. Dovresti vedere la seguente schermata:

Seleziona la lingua e il paese dei metadati, quindi fai clic sul pulsante Avanti. Dovresti vedere la seguente schermata:

Seleziona l'opzione desiderata e fai clic sul pulsante Avanti. Dovresti vedere la seguente schermata:

Fare clic sul pulsante Fine. Dovresti vedere la pagina di accesso di Jellyfin:

Fornisci il tuo nome utente, password e fai clic sul pulsante Accedi. Dovresti vedere la dashboard di Jellyfin nella seguente schermata:

Ora puoi aggiungere i tuoi file multimediali alla libreria e accedervi tramite Internet.

Proteggi Jellyfin con Lets Encrypt

Successivamente, dovrai installare il pacchetto client Certbot per installare la gestione di Lets Encrypt SSL. Innanzitutto, installa Certbot con il seguente comando:

apt-get install python3-certbot-nginx -y

Al termine dell'installazione, esegui il seguente comando per installare Lets Encrypt SSL sul tuo sito web:

certbot --nginx -d jellyfin.yourdomain.com

Ti verrà chiesto di fornire un indirizzo email valido e di accettare i termini di servizio come mostrato di seguito:

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

Successivamente, scegli se reindirizzare o meno il traffico HTTP su HTTPS come mostrato di seguito:

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
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

Digita 2 e premi Invio per completare l'installazione. Dovresti vedere il seguente output:

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.

Ora il tuo sito web è protetto con Lets Encrypt SSL. Puoi accedervi in modo sicuro utilizzando l'URL https://jellyfin.yourdomain.com.

Conclusione

Congratulazioni! hai installato e configurato correttamente Jellyfin con Nginx e Lets Encrypt SSL sul server Ubuntu 20.04. Ora puoi eseguire lo streaming dei tuoi contenuti multimediali e accedervi dal browser Web o utilizzando l'applicazione Jellyfin. Non esitate a chiedermi se avete domande.