Skip to content

Instantly share code, notes, and snippets.

@spikegrobstein
Last active July 26, 2025 20:11
Show Gist options
  • Save spikegrobstein/4384954 to your computer and use it in GitHub Desktop.
Save spikegrobstein/4384954 to your computer and use it in GitHub Desktop.
nginx config for proxying requests for plex over a hostname-based virtualhost.
upstream plex-upstream {
# change plex-server.example.com:32400 to the hostname:port of your plex server.
# this can be "localhost:32400", for instance, if Plex is running on the same server as nginx.
server plex-server.example.com:32400;
}
server {
listen 80;
# server names for this server.
# any requests that come in that match any these names will use the proxy.
server_name
tv
plex
tv.example.com
plex.example.com;
# this is where everything cool happens (you probably don't need to change anything here):
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
# this fixes a bug where you get permission issues when accessing the web dashboard
if ($http_x_plex_device_name = '') {
rewrite ^/$ http://$http_host/web/index.html;
}
# set some headers and proxy stuff.
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_redirect off;
# include Host header
proxy_set_header Host $http_host;
# proxy request to plex server
proxy_pass http://plex-upstream;
}
}
@dsculptor
Copy link

dsculptor commented Aug 24, 2021

Update: The original gist without the proxy_set_headers as mentioned in follow-ups works well.
Thanks @spikegrobstein.

@mStirner
Copy link

mStirner commented Jul 26, 2025

Broken with the latest version/after update. (v4.147.1)
Local client detection breaks, which shows a popup where you need to pay to access "a remote server".

@spikegrobstein
Copy link
Author

Ah darn. Thanks for the heads up. 12 and a half years isn't bad!

When I'm by a computer I'll need to mark this as no longer working.

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