Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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

This comment has been minimized.

Copy link

@gogonaft gogonaft commented Apr 23, 2017

Useful for latest version of Plex. Thanks!

@andrej-peterka

This comment has been minimized.

Copy link

@andrej-peterka andrej-peterka commented Apr 29, 2017

Worked for me on version 1.5.5.3634, thanks a lot!

@C-Duv

This comment has been minimized.

Copy link

@C-Duv 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.

@mxplusb

This comment has been minimized.

Copy link

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

This comment has been minimized.

Copy link

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

This comment has been minimized.

Copy link

@Drehmini Drehmini commented Dec 8, 2018

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

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