Proxying Apache Connections to Multiple Applications

I was having issues getting Apache working with Plex, OwnCloud, and SyncThing at the same time on a new server. I wanted to have a reverse proxy set up, so instead of

I could have

Apache’s reverse proxy functionality caters to this need.
Each app gets its own ProxyPass, telling Apache what to do with incoming requests.
SyncThing didn’t like operating without a trailing slash in the URL, so a rewrite rule was created to do this for the user.
OwnCloud, since it doesn’t require operating on a separate port, simply goes around the proxy.
Everything else falls into the catchall, which redirects the user to Plex.

#redirect everything to SSL
<VirtualHost *:80>
        RewriteEngine On
        RewriteCond %{HTTPS} off
        RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}

<VirtualHost *:443>

        #SSL configuration
        SSLEngine on
        SSLCertificateFile /etc/ssl/certs/server.crt
        SSLCertificateKeyFile /etc/ssl/private/server.key
        SSLCertificateChainFile /etc/ssl/certs/intermediate.crt
        #begin the proxying
        ProxyRequests Off
        ProxyPreserveHost On

        #let owncloud pass straight through
        ProxyPass /owncloud !

        #syncthing doesn't work without a trailing slash in browser URL
        RewriteRule ^/syncthing$ /syncthing/ [R]
        ProxyPass /syncthing/
        ProxyPassReverse /syncthing/

        #default go to plex
        ProxyPass /
        ProxyPassReverse /

        RewriteEngine on
        RewriteCond %{REQUEST_URI} !^/web
        RewriteCond %{HTTP:X-Plex-Device} ^$
        RewriteRule ^/$ /web/$1 [R,L]

Leave a Reply

Your email address will not be published. Required fields are marked *