I am trying to build an Apache reverse proxy to make a set of servers accessible through a single point of access. The servers all offer a web admin interface on port 3000, and I intend to present all of them as directories on the reverse proxy. The interfaces contain local links which must of course be rewritten to go to the correct server's subdirectory on the proxy.
I can achieve the required behaviour with configuration snippets like this for each server individually:
<Location /testadmin-warsaw/>
ProxyPass http://warsaw.example.com:3000/
ProxyPassReverse /
ProxyHTMLEnable On
ProxyHTMLURLMap / /testadmin-warsaw/ L
RequestHeader unset Accept-Encoding
</Location>
As this gets rather tedious and error-prone as servers come and go, I am aiming for a dynamic configuration. According to the Apache documentation, the following should work:
<LocationMatch "^/testadmin-(?<OFFICENAME>\w+)/(.*)$">
ProxyPassMatch http://$1.example.com:3000/$2
ProxyPassReverse /
ProxyHTMLEnable On
ProxyHTMLInterp On
ProxyHTMLURLMap / /testadmin-${env:MATCH_OFFICENAME|unknown}/ VL
RequestHeader unset Accept-Encoding
</LocationMatch>
<LocationMatch>
would set the environment variable MATCH_OFFICENAME
to the office name part of the directory, and ProxyHTMLURLMap
would insert this name at the appropriate place in the rewritten links.
But when I test that configuration, a link originally pointing to /other/page.html
is rewritten to /testadmin-unknown/other/page.html
instead of /testadmin-warsaw/other/page.html
as intended. In other words, ProxyHTMLURLMap
acts as if the environment variable MATCH_OFFICENAME
was unset.
If I omit the env:
part and put just /testadmin-${MATCH_OFFICENAME}/
as the to-pattern, Apache logs a warning: "AH00111: Config variable ${MATCH_OFFICENAME} is not defined".
Where's my mistake?
The syntax without
env:
is correct. TheAH00111
warning message it produces is spurious, as per Apache Bug #58467.The configuration:
works as intended, except for the spurious warning at each startup.