2

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.

Chris Seymour
  • 83,387
  • 30
  • 160
  • 202

1 Answers1

2

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)

Dusan Bajic
  • 10,249
  • 3
  • 33
  • 43