Files
docudjeex/content/3.serveex/5.media/1.plex.md
2025-07-20 17:58:30 +00:00

314 lines
9.9 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

---
navigation: true
title: Plex
main:
fluid: false
---
:ellipsis{left=0px width=40rem top=10rem blur=140px}
# Plex
::alert{type="info"}
🎯 **Objectives:**
- Install Plex
- Install Tautulli
- Access media from outside your network
::
[Plex](https://www.plex.tv/fr/) is a self-hosted video streaming platform for managing your movie or TV show library and playing them locally or remotely. Plex has apps for TV, Android, iOS, Windows, and macOS, allowing you to stream your library just like Netflix.
With *Plex Pass*, you can also organize and play your music content similar to Spotify, the difference being that its your content, hosted and streamed from your server.
![picture](/img/serveex/plex.png)
We'll also install [Tautulli](https://docs.linuxserver.io/images/docker-tautulli/), a tool that provides detailed stats about Plex. As always, we'll use linuxserver.io images where possible.
- [More info on the Plex container](https://docs.linuxserver.io/images/docker-plex)
- [More info on the Tautulli container](https://docs.linuxserver.io/images/docker-tautulli/)
::alert{type="info"}
:::list{type="info"}
- Youll need to create a *Plex.tv* account. You dont need to expose your Plex service; it will be accessible through the platform. Your Plex server will be manageable directly from your account.
:::
::
## Install Plex
---
Folder structure:
```console
root
├── docker
│ ├── plex
│ │ ├── compose.yml
│ │ ├── .env
│ │ ├── config
│ │ └── transcode
│ └── tautulli
│ └── config
└── media
├── tvseries
├── movies
└── library
```
Create the `movies`, `tvseries`, and `library` folders in `/media`:
```sh
mkdir -p /media/movies /media/library /media/tvseries
```
Open Dockge in your browser and click `compose`.
Name the stack `plex` and add the following config:
```yaml
---
services:
linuxserver_plex:
image: ghcr.io/linuxserver/plex:amd64-latest
container_name: plex
network_mode: host
environment:
- PUID=${PUID}
- PGID=${GUID}
- TZ=Europe/Paris
- VERSION=docker
volumes:
- /docker/plex/config:/config
- /docker/plex/transcode:/transcode
- /media:/media
restart: unless-stopped
mem_limit: 4096m
mem_reservation: 2048m
devices:
- /dev/dri:/dev/dri
tautulli:
image: lscr.io/linuxserver/tautulli:latest
container_name: tautulli
environment:
- PUID=${PUID}
- PGID=${GUID}
- TZ=Europe/Paris
volumes:
- /docker/tautulli/config:/config
ports:
- 8181:8181
restart: unless-stopped
```
::alert{type="success"}
✨ Add the Watchtower label to each container to automate updates:
```yaml
services:
plex:
#...
labels:
- com.centurylinklabs.watchtower.enable=true
tautulli:
#...
labels:
- com.centurylinklabs.watchtower.enable=true
```
::
Find your PUID and GUID by running:
```shell
id username
```
Fill in your `.env` file with the retrieved values, for example:
```properties
PUID=1000
GUID=1000
```
Deploy the stack.
The local interface is available at `http://yourserverip:32400/web/index.html`.
Tautulli is accessible at `http://yourserverip:8181`.
::alert{type="warning"}
:::list{type="warning"}
- You must be on your local network during Plex's initial setup. Otherwise, the URL will redirect to your Plex account without detecting your server. A VPN won't help. If you have no choice, [you can handle the setup remotely via SSH tunnel](https://support.plex.tv/articles/200288586-installation/#toc-2).
:::
::
## Configure Plex
---
Plex offers a range of free movies/shows. After creating your account, I recommend disabling everything in the _Online Services_ section to keep your library clean.
Then go to the _Remote Access_ section and manually select a port (well use `1234`). It's best not to use the default port.
![picture](/img/serveex/plex-port.png)
- On your router, forward TCP port `1234` to port `32400` for your servers IP using [NAT rules](/general/networking/nat).
- Once done, return to Plex to verify that remote access is functional.
::alert{type="danger"}
:::list{type="danger"}
- **If it fails:** check your firewall rules and allow port `32400` on your server.
:::
::
- If you have PlexPass and a GPU or iGPU, enable *hardware acceleration* in the _Transcoder_ section.
- In _Settings > Library_, enable _Update my library automatically_.
- In _Manage > Library_, add or edit libraries and point to `/media/movies` for movies and `/media/tvseries` for series.
And thats it! You now have a working Plex server!
Simply add your media to `/media/movies` and `/media/tvseries` on your server. You can then install the Plex app on your devices and watch your favorite content locally or remotely.
::alert{type="info"}
:::list{type="info"}
- If your media is stored on a network disk (e.g. NAS or external hard drive over the network), refer to the [Samba mount guide](/general/networking/samba) so Plex can access it.
:::
::
## Expose Tautulli with Swag
---
You dont need to expose Plex, as it's accessible via your Plex account on plex.tv.
However, you may want to expose Tautulli so you can view stats from a simple URL when you're not home.
::alert{type="info"}
:::list{type="info"}
- We assume you have the subdomain `tautulli.mydomain.com` with a `CNAME` pointing to `mydomain.com` in your [DNS zone](/general/networking/dns). And of course, [unless you use Cloudflare Zero Trust](/serveex/security/cloudflare), your box's port `443` must be forwarded to your server's port `443` in [NAT rules](/general/networking/nat).
:::
::
Go to Dockge and edit SWAGs compose file by adding Tautullis network:
```yaml
services:
swag:
container_name: # ...
# ...
networks: # Attach container to custom network
# ...
- tautulli # Name of the declared network
networks: # Define the custom network
# ...
tautulli: # Declared network name
name: tautulli_default # Actual external network name
external: true # Marks it as externally defined
```
Redeploy the stack and wait for SWAG to be fully operational.
::alert{type="info"}
:::list{type="info"}
- Here we assume the Tautulli network name is `tautulli_default`. You can check the connection by visiting SWAGs dashboard at `http://yourserverip:81`.
:::
::
Copy and rename the file `tautulli.subdomain.conf.sample` to `tautulli.subdomain.conf`, then edit it:
::alert{type="success"}
**Tip:** Use [File Browser](/serveex/files/file-browser) to navigate and edit files instead of using terminal commands.
::
```shell
sudo cp /docker/swag/config/nginx/proxy-confs/tautulli.subdomain.conf.sample /docker/swag/config/nginx/proxy-confs/tautulli.subdomain.conf
sudo vi /docker/swag/config/nginx/proxy-confs/tautulli.subdomain.conf
```
Ensure the configuration matches the following. If needed, press `i` to edit:
```nginx
## Version 2023/05/31
# make sure that your tautulli container is named tautulli
# make sure that your dns has a cname set for tautulli
server {
listen 443 ssl;
listen [::]:443 ssl;
server_name tautulli.*;
include /config/nginx/ssl.conf;
client_max_body_size 0;
# enable for ldap auth (requires ldap-location.conf in the location block)
#include /config/nginx/ldap-server.conf;
# enable for Authelia (requires authelia-location.conf in the location block)
#include /config/nginx/authelia-server.conf;
# enable for Authentik (requires authentik-location.conf in the location block)
#include /config/nginx/authentik-server.conf;
location / {
# enable the next two lines for http auth
#auth_basic "Restricted";
#auth_basic_user_file /config/nginx/.htpasswd;
# enable for ldap auth (requires ldap-server.conf in the server block)
#include /config/nginx/ldap-location.conf;
# enable for Authelia (requires authelia-server.conf in the server block)
#include /config/nginx/authelia-location.conf;
# enable for Authentik (requires authentik-server.conf in the server block)
#include /config/nginx/authentik-location.conf;
include /config/nginx/proxy.conf;
include /config/nginx/resolver.conf;
set $upstream_app tautulli;
set $upstream_port 8181;
set $upstream_proto http;
proxy_pass $upstream_proto://$upstream_app:$upstream_port;
}
location ~ (/tautulli)?/api {
include /config/nginx/proxy.conf;
include /config/nginx/resolver.conf;
set $upstream_app tautulli;
set $upstream_port 8181;
set $upstream_proto http;
proxy_pass $upstream_proto://$upstream_app:$upstream_port;
}
location ~ (/tautulli)?/newsletter {
include /config/nginx/proxy.conf;
include /config/nginx/resolver.conf;
set $upstream_app tautulli;
set $upstream_port 8181;
set $upstream_proto http;
proxy_pass $upstream_proto://$upstream_app:$upstream_port;
}
location ~ (/tautulli)?/image {
include /config/nginx/proxy.conf;
include /config/nginx/resolver.conf;
set $upstream_app tautulli;
set $upstream_port 8181;
set $upstream_proto http;
proxy_pass $upstream_proto://$upstream_app:$upstream_port;
}
}
```
::alert{type="success"}
✨ You can protect this app with Authentik by removing the `#` before `include /config/nginx/authentik-server.conf;` and `include /config/nginx/authentik-location.conf;`. Dont forget to [create an application and provider in Authentik](/serveex/security/authentik#protecting-an-app-via-reverse-proxy).
::
Press `Esc` then save and quit by typing `:x`
Wait a few minutes, then open `http://tautulli.mydomain.com` in your browser.
::alert{type="danger"}
:::list{type="danger"}
- **If it fails:** check your firewall rules.
:::
::
And you're done!