Skip to content

Instantly share code, notes, and snippets.

@ometa
Last active April 20, 2024 15:50
Show Gist options
  • Star 13 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save ometa/654376bf0e12e6131f2b809b3dc0f151 to your computer and use it in GitHub Desktop.
Save ometa/654376bf0e12e6131f2b809b3dc0f151 to your computer and use it in GitHub Desktop.
NGINX reverse proxy in front of Plex media server v1.3.3.3148
# This example assumes the NGINX proxy is on the same host as the Plex Media Server.
# To configure Plex Media Server to serve requests without requiring authentication,
# ensure that your LAN subnet is correctly added to the advanced server setting called
# "List of IP addresses and networks that are allowed without auth". Example:
# 192.168.0.1/24
upstream plex-upstream {
server 127.0.0.1:32400;
}
server {
listen 80;
server_name plex tv plex.example.com tv.example.com;
location / {
# If a request to / comes in, 301 redirect to the main plex page,
# but only if it doesn't contain the X-Plex-Device-Name header or query argument.
# This fixes a bug where you get permission issues when accessing the web dashboard.
set $test "";
if ($http_x_plex_device_name = '') {
set $test A;
}
if ($arg_X-Plex-Device-Name = '') {
set $test "${test}B";
}
if ($test = AB) {
rewrite ^/$ http://$http_host/web/index.html;
}
proxy_redirect off;
proxy_buffering off;
# Spoof the request as coming from ourselves since otherwise Plex will block access, e.g. logging:
# "Request came in with unrecognized domain / IP 'tv.example.com' in header Referer; treating as non-local"
proxy_set_header Host $server_addr;
proxy_set_header Referer $server_addr;
proxy_set_header Origin $server_addr;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Plex-Client-Identifier $http_x_plex_client_identifier;
proxy_set_header Cookie $http_cookie;
## Required for Websockets
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_read_timeout 36000s; # Timeout after 10 hours
proxy_next_upstream error timeout invalid_header http_500 http_502 http_503 http_504;
proxy_pass http://plex-upstream;
}
}
@Bun-Bun
Copy link

Bun-Bun commented Mar 1, 2023

@afteroot which config are you looking for?

@afteroot
Copy link

afteroot commented Mar 1, 2023

@afteroot which config are you looking for?

On which you get 502 error, maybe i can help you with config

@ometa
Copy link
Author

ometa commented Mar 27, 2023

I'm glad this is still proving helpful!

@Mendas88
Copy link

Working with Plex as of version 4.125.1

@Bun-Bun
Copy link

Bun-Bun commented Apr 20, 2024

@afteroot which config are you looking for?

On which you get 502 error, maybe i can help you with config

I'm not sure which config you are referring. If you mean the nginx config it's the same config that is posted here. I drop it in place and got bad gateway.

@afteroot
Copy link

@Bun-Bun , in that way you need to check that your upstream is correct

upstream plex-upstream {
  server 127.0.0.1:32400;
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment