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;
}
}
@gogonaft
Copy link

Useful for latest version of Plex. Thanks!

@andrej-peterka
Copy link

Worked for me on version 1.5.5.3634, thanks a lot!

@C-Duv
Copy link

C-Duv commented Oct 20, 2017

Thanks a lot! 👍

I had this issue since a version where they blocked accessing Plex web GUI using FQDN other than the hostname... Had to use IP address since then... 😩

I confirm your gist is working with version 1.8.4.4249.

@siennathesane
Copy link

siennathesane commented Feb 14, 2018

I can confirm this works with version 1.10.1.4602. I am using URL rewrite to permanently redirect HTTP to HTTPS like this: rewrite ^ https://$server_name$request_uri?$query_string permanent. It works perfectly for me.

@Kline-
Copy link

Kline- commented Sep 17, 2018

Plex version 1.13.5.5332-21ab172de and receiving the "Request came in with unrecognized domain / IP 'tv.example.com' in header Referer; treating as non-local" in logs. Been playing around with a lot of settings to no avail. Any ideas?

@Drehmini
Copy link

Drehmini commented Dec 8, 2018

This works well for a server on the same network (after modifying the upstream server setting).

@afteroot
Copy link

Thanks, works... tested on plexmediaserver 1.24.3.5033-757abe6b4

@Bun-Bun
Copy link

Bun-Bun commented Feb 10, 2023

I get 502 bad gateway trying to use this. Redirect appears to be working but bad gateway.

plex server responds locally, tested with ssh tunnel.

@afteroot
Copy link

@Bun-Bun please show your config

@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