Using NginX Route to Plex Server Behind Firewall.

Description

If you have a router and want to limit access from the outside world to all the computers inside your home, then you will probably want to set up a server in a DMZ or forward specific ports to it. This open server can then route traffic to anything behind the firewall for you — acting as a proxy. I have used both Apache and Nginx, I like both, but In this article I will show an example using Nginx. Nginx has been proven to be able to handle more concurrent requests than apache and it is very lightweight.

Directions

There are lots of tutorials on the internet that show how to install and configure nginx. The general idea is when you install nginx there are to folders (usually in /etc/nginx/) called sites-available and sites-enabled. Good practice is to make a conf file inside the sites-available directory. Then execute the following command:

nginx -t

Once the configuration file is syntactically correct you can do a symbolic link to the same filename in sites-enabled. The following configuration shows one of my configuration files that routes request to plex.domainname.com to my plex server behind the firewall. If own a domain name then you need to edit the zone file and make an A record that points to the IP address of the router. When you then request plex..com the traffic will hit your router, go through the firewall to the server, and be proxied to another location via nginx.




NGinX Server Diagram

plex.conf
[enlighter language=”json”]
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 :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 plex..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;
}
}
[/enlighter]




Comments are closed.