Skip to content

Instantly share code, notes, and snippets.

@devster31
Forked from spikegrobstein/nginx.conf
Last active July 9, 2021 09:35
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save devster31/bef6eff9decf5ad34543 to your computer and use it in GitHub Desktop.
Save devster31/bef6eff9decf5ad34543 to your computer and use it in GitHub Desktop.
to add plex as a subdomain
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;
error_page 497 https://$host:$server_port$request_uri;
# 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;
}
# include Host header
proxy_set_header Host $http_host;
# 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;
#extra options
proxy_buffering off;
proxy_next_upstream error timeout invalid_header http_500 http_502 http_503 http_504;
## Required for Websockets only
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 request to plex server
proxy_pass http://plex-upstream;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment