Pretty URLs - Serving Plex from behind a proxy using mod_proxy and Apache

By · Published · apache, networking, plex, howto

I'm obsessed with pretty URLs. I admit it. I love looking at a properly formatted URL that just looks nice.

I'm slowly converting our internal media library over to Plex now that it is available on the new AppleTV. In doing that, I noticed that the Plex web interface serves, by default, serves from port 32400. So the URL ends up looking somthing like this:

http://172.16.104.4:32400/web/index.html

Twitch.

I care about this stuff, even on my internal network. Wouldn't that be better if it was something like:

http://plex.internal.domain/

Much easier to remember and much prettier too. And fortunately, with a little bit of work, very possible with Apache and mod_proxy!

Installing Apache on the box of your choice is beyond the scope of this document. I'm actually running Plex and Apache from my Drobo 5N. You could theoretically even proxy between two physically separate machines; Plex lives on one machine an Apache and mod_proxy lives on another (I've used this method in the past to selectively expose things at home over a VPN when I needed to have a customer look at something).

If you're curious how to do that on the Drobo, it's available as a Drobo app that can be installed from Drobo dashboard. If it doesn't show up, it may already be installed. You can shell to the Drobo and go to the /mnt/DroboFS/Shares/DroboApps/apache directory.

Either way, create a new vhost file however you normally would with the following configuration:

<VirtualHost *:80>
    ServerName plex.internal.domain

    ProxyRequests Off
    ProxyPreserveHost On
    ProxyPass /:/ ws://localhost:32400/:/
    ProxyPassReverse /:/ ws://localhost:32400/:/

    ProxyPass / http://localhost:32400/
    ProxyPassReverse / http://localhost:32400/

    RewriteEngine on
    RewriteCond %{REQUEST_URI} !^/web
    RewriteCond %{HTTP:X-Plex-Device} ^$
    RewriteCond %{QUERY_STRING} (^|&)X-Plex-Device=(&|$) [OR]
    RewriteCond %{QUERY_STRING} !(^|&)X-Plex-Device=
    RewriteRule ^/$ /web/$1 [R,L]

   <Proxy *>
        Order deny,allow
        Allow from all
        Require all granted
    </Proxy>
</VirtualHost>

A quick note about what's going on here. We're basically proxying everything we receive back to ourselves on a different port. But websockets need to be handled differently. In this case, Plex's websockets path /:/ has to be passed back to the proxy using websockets, so it needs a separate entry. Without this it "works" but you won't get notifications or logging.

Save, close, and reload apache. That's it! You should now be able to access Plex through plex.internal.domain or whatever domain you have chosen to use. Note that this only affects the web interface. Client streaming works differently and isn't relevant to this method.

( Comments )

Did something I wrote help you out?

That's great! I don't earn any money from this site - I run no ads, sell no products and participate in no affiliate programs. I do this solely because it's fun; I enjoy writing and sharing what I learn.

All the same, if you found this article helpful and want to show your appreciation, here's my Amazon.com wishlist.


Related Posts

Automatically Provisioning Polycom Phones

Google Chrome, Mac OS X and Self-Signed SSL Certificates


comments powered by Disqus