Plex: Difference between revisions

From Dave-Wiki
No edit summary
No edit summary
 
Line 27: Line 27:
# After you open the SSH connection, point your browser to [http://127.0.0.1:32400 http://127.0.0.1:32400]
# After you open the SSH connection, point your browser to [http://127.0.0.1:32400 http://127.0.0.1:32400]


===nginx Reverse Proxy===
==nginx Reverse Proxy==


Use this nginx config if you want to use nginx as a reverse proxy frontend for Plex (so you can use SSL certs, etc.).
Use this nginx config if you want to use nginx as a reverse proxy frontend for Plex (so you can use SSL certs, etc.).

Latest revision as of 20:21, 3 February 2026

Summary

Plex Media Server is a software application that organizes and streams your personal collection of movies, TV shows, music, photos, and more to nearly any device. It runs on a computer, NAS, or compatible server hardware, cataloging media with rich metadata like posters, episode details, and album art for a polished, Netflix-like interface. Once set up, Plex lets you stream content locally on your home network or remotely over the internet, and it supports user accounts, parental controls, transcoding for different devices, and optional features like live TV and DVR with a tuner. It’s widely used as an all-in-one hub for managing and enjoying digital media libraries.

Common Tasks

Plex Server Not Authorized

In some rare situations, you may find yourself “locked out” from being able to access your Plex Media Server and unable to directly access the server settings. One of the most common causes for this is if your server is signed in to one account (perhaps one used with an old, previous installation) and your web app is signed in with a different account that doesn’t have permission to connect to the server.

It can also occur after you change your password, remove your server “Device” entry, or otherwise invalidate the existing authentication token that your server uses.

You can try the instructions here: [1]

But likely you'll need to "re-claim" your server. See instructions below.

Claim Plex Server

This must be done by accessing http://127.0.0.1:32400 locally on the Plex server. Of course, this is difficult to do on a headless Linux box with no GUI. So we tunnel!

You can pretty easily tunnel with PuTTY:

  1. Go to Connection > SSH > Tunnels
  2. Add a new forwarded port:
    Source port: 32400
    Destination: 127.0.0.1:32400
  3. After you open the SSH connection, point your browser to http://127.0.0.1:32400

nginx Reverse Proxy

Use this nginx config if you want to use nginx as a reverse proxy frontend for Plex (so you can use SSL certs, etc.).

Of course, replace yourfqdn.com with your actual FQDN.

user nginx;
worker_processes auto;
error_log /var/log/nginx/error.log;
pid /run/nginx.pid;

# Load dynamic modules. See /usr/share/doc/nginx/README.dynamic.
include /usr/share/nginx/modules/*.conf;

events {
    worker_connections 1024;
}

http {
    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for"';

    access_log  /var/log/nginx/access.log  main;

    sendfile            on;
    tcp_nopush          on;
    tcp_nodelay         on;
    keepalive_timeout   65;
    types_hash_max_size 2048;

    include             /etc/nginx/mime.types;
    default_type        application/octet-stream;

    ssl_session_cache shared:SSL:1m;
    ssl_session_timeout  10m;
    
    upstream plex_backend {
        server 127.0.0.1:32400;
        keepalive 32;
    }

	#Plex has A LOT of javascript, xml and html. This helps a lot, but if it causes playback issues with devices turn it off. (Haven't encountered any yet)
	gzip on;
	gzip_vary on;
	gzip_min_length 1000;
	gzip_proxied any;
	gzip_types text/plain text/css text/xml application/xml text/javascript application/x-javascript image/svg+xml;
	gzip_disable "MSIE [1-6]\.";

	#Nginx default client_max_body_size is 1MB, which breaks Camera Upload feature from the phones.
	#Increasing the limit fixes the issue. Anyhow, if 4K videos are expected to be uploaded, the size might need to be increased even more
	client_max_body_size 100M;

	#Forward real ip and host to Plex
	proxy_set_header Host $host;
	proxy_set_header X-Real-IP $remote_addr;
	#When using ngx_http_realip_module change $proxy_add_x_forwarded_for to '$http_x_forwarded_for,$realip_remote_addr'
	proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
	proxy_set_header X-Forwarded-Proto $scheme;
	proxy_set_header Sec-WebSocket-Extensions $http_sec_websocket_extensions;
	proxy_set_header Sec-WebSocket-Key $http_sec_websocket_key;
	proxy_set_header Sec-WebSocket-Version $http_sec_websocket_version;

	#Websockets
	proxy_http_version 1.1;
	proxy_set_header Upgrade $http_upgrade;
	proxy_set_header Connection "Upgrade";

        #Disables compression between Plex and Nginx, required if using sub_filter below.
	#May also improve loading time by a very marginal amount, as nginx will compress anyway.
        #proxy_set_header Accept-Encoding "";

	#Buffering off send to the client as soon as the data is received from Plex.
	proxy_redirect off;
	proxy_buffering off;

    server {
        return 301 https://$host$request_uri;
        listen      80;
        #server_name _;
        server_name  plex.yourfqdn.com;
    }

    server {
        listen       443 ssl http2 default_server;
        listen       [::]:443 ssl http2 default_server;
        server_name  plex.yourfqdn.com;

        ssl_certificate "/etc/pki/tls/certs/plex.cer";
        ssl_certificate_key "/etc/pki/tls/private/plex.key";
        ssl_ciphers PROFILE=SYSTEM;
        ssl_prefer_server_ciphers on;

        location / {
            proxy_pass http://plex_backend;
        }

        error_page 404 /404.html;
            location = /40x.html {
        }

        error_page 500 502 503 504 /50x.html;
            location = /50x.html {
        }
    }

}