How to reverse proxy Plex with nginx (from a folder)


Adding a reverse proxy for the Plex web UI in nginx is a little harder than just passing all its requests to port 3200. Luckily, with just one snippet of nginx configuration, we can reverse proxy Plex easily, even with authentication. My configuration allows you to run Plex from within a folder (e.g., so you don't need to add a special subdomain just to access Plex.


Setting up the reverse proxy

In your preferred server block, add the following location block. I will go over the most important lines to explain why they are included.

location /plex/ {
    rewrite /plex(/.*) $1 break;

    proxy_pass http://localhost:3200;
    proxy_http_version 1.1;
    proxy_set_header Accept-Encoding "";
    proxy_set_header Upgrade $http_upgrade;
    proxy_set_header Connection 'upgrade';
    proxy_set_header Host $http_host;
    proxy_cache_bypass $http_upgrade;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_redirect off;

    sub_filter '/web/' '/plex/web/';
    sub_filter_types *;
    sub_filter_once off;

Setting up Plex

If you restart your nginx service and try to visit your new Plex URL, you might get the message that you need to login. If you want to be able to access your Plex server without authentication, even if goes down (which it often does), enter your local IP range (e.g. in the Plex settings under Network > List of IP addresses and networks that are allowed without auth. This could mean, however, that everyone who's able to access your reverse proxy url will be able to access your Plex server in this way, since Plex only sees "local" requests (I could be wrong, though -- I haven't tested this). You might also need to enter your server's new URL in the Plex settings under Network > Custom server access URLs.