使用 apache 进行动态主机名和端口代理

Dynamic hostname and port proxying with apache

是否可以像这样使用 apache 动态代理主机名和端口:

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

我试过使用 ProxyPassMatch:

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

但是 apache 抛出语法错误 AH00526。这是使用 apache 2.4.7.

来自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.

我能想到的唯一解决方法是使用 mod_rewrite with [P] 标志:

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

(但这会带来性能损失,同时请记住,对于这种动态代理,您不能使用 ProxyPassReverse 来调整 HTTP 重定向响应中的 URL)