iiSeymour iiSeymour - 16 days ago 6
Apache Configuration Question

Dynamic hostname and port proxying with apache

Is it possible to use apache to proxy a hostname and port dynamically like so:

/<PORT>/<HOSTNAME> -> http://<HOSTNAME>.domain.local:<PORT>


I've tried the using
ProxyPassMatch
:

ProxyPassMatch "^/([0-9]+)/(host-[0-9]+)$" "http://$2.domain.local:$1"


But apache throws a syntax error AH00526. This is using apache 2.4.7.

Answer

From Apache Docs:

The URL argument must be parsable as a URL before regexp substitutions (as well as after). This limits the matches you can use.

The only workaround I can think of is to use mod_rewrite with [P] flag:

RewriteEngine On
RewriteRule "^/([0-9]+)/(host-[0-9]+)$" "http://$2.domain.local:$1" [P]

(But this comes with performance penalty, and also keep in mind that with such dynamic proxying you can not use ProxyPassReverse to adjust the URL in HTTP redirect responses)