问题
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.
回答1:
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)
来源:https://stackoverflow.com/questions/40749739/dynamic-hostname-and-port-proxying-with-apache