Configure Apache to ProxyPass jekyll serve
Motivation
This blog is written with jekyll and I wanted to be able to browse the drafts version from my Apache development portal. I wanted to keep Jekyll’s serve function on all the time, so I could write and view rendered posts at my leisure.
Process
Configure ProxyPass
Behind a password-protected location, I added the following configuration section:
<Location "/jekyll">
ProxyPass "http://localhost:4000"
ProxyPassReverse "/"
</Location>
Configure ProxyHTML
There were some resources in the header that used absolute URLs, so I decided to use mod_proxy_html to rewrite those remaining URLs. I thought about running jekyll with a temporary development configuration. Using mod proxy _config.yaml is set up for deployment and can stay that way.
I had to copy the default HTMLLinks from the Apache docs into a .conf file to be included (or into the <Location> section directly) because using it resets the definitions in that scope. I opted to use a configuration fragment on the possibility I would need the list again somewhere.
<Location "/jekyll">
ProxyPass "http://localhost:4000"
ProxyPassReverse "/"
# Rewrite HTML links
ProxyHTMLEnable On
ProxyHTMLLinks "use" "xlink:href"
# Include default ProxyHTMLLinks directives
Include "conf-available/ProxyHTMLLinks.conf"
# rewrite all urls in the HTML to begin with our baseurl
ProxyHTMLURLMap "/" "/jekyll/"
</Location>