I’m hosting Fathom on my domain at /fathom. It runs its own web server, so I’ve done this using a reverse proxy that makes the Fathom server accessible at that virtual directory. Their self-hosting instructions do have an example configuration for using Fathom with a reverse proxy through NGINX, but not Apache.
Fortunately the idea’s the same, so adapting it for Apache doesn’t involve too much. It does mean modifying the httpd.conf (or appropriate site-specific config file), and enabling a few additional Apache modules.
The Apache modules needed are mod_proxy, mod_proxy_http and mod_substitute. These can be enabled using
a2enmod and restarting Apache:
sudo a2enmod proxy proxy_http substitute && sudo service apache2 restart
Now to enable the reverse proxy, I’ve added a new
Location directive the
VirtualHost in my site’s config file:
A little more on what each of those directives are doing:
Creates an entry point at the URL in the
Locationdirective (the first line, in this case it’s /fathom), which in turn forwards those requests on to the Fathom server defined in this
Replaces redirects sent from Fathom (in the
Locationheader) with the location that the client browser can access. In other words, when Fathom tries to redirect to an internal Login page (127.0.0.1:8999/login), this directive tells Apache to replace that with an externally-accessible URL (/fathom/login).
Fathom’s example NGINX configuration explicitly passes on the Host header from the proxy to the upstream server (Fathom), so it’s safe to assume we should too.
ProxyHTMLURLMap ^(.*)$ /fathom/$1 [R]
These next few directives replace URLs in various HTML elements before sending them back to the browser. For example,
<script>tags will need to be updated to point to the virtual directory (subfolder). Including the
proxy_html.conffile imports a default mapping of attributes to elements so that Apache knows which attributes on which elements to update.
Substituteuses a sed-like syntax for replacing text.
Leave a Reply