0

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?

2
  • Isn't the %-sign used for env vars in apache? ProxyHTMLURLMap / /testadmin-%{env:MATCH_OFFICENAME}/ VL May 31, 2020 at 21:35
  • That's what I thought initially, too, but it does not work at all. It produces /testadmin-%{env:MATCH_OFFICENAME}/other/page.html literally with no substitution happens at all. According to the Apache manual entry for ProxyHTMLURLMap, you have to use the $ sign, Jun 1, 2020 at 9:46

1 Answer 1

0

The syntax without env: is correct. The AH00111 warning message it produces is spurious, as per Apache Bug #58467.

The configuration:

<LocationMatch "^/testadmin-(?<OFFICENAME>\w+)/(.*)$">
        ProxyPassMatch   http://$1.example.com:3000/$2
        ProxyPassReverse /
        ProxyHTMLEnable  On
        ProxyHTMLInterp  On
        ProxyHTMLURLMap  / /testadmin-${MATCH_OFFICENAME|unknown}/ VL
        RequestHeader    unset Accept-Encoding
</LocationMatch>

works as intended, except for the spurious warning at each startup.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .