是否可以使用 apache 动态代理主机名和端口,如下所示:
/<PORT>/<HOSTNAME> -> http://<HOSTNAME>.domain.local:<PORT>
我尝试过使用ProxyPassMatch
:
ProxyPassMatch "^/([0-9]+)/(host-[0-9]+)$" "http://$2.domain.local:$1"
但是 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与 [P]标志:
RewriteEngine On
RewriteRule "^/([0-9]+)/(host-[0-9]+)$" "http://$2.domain.local:$1" [P]
(但这会带来性能损失,并且请记住,使用此类动态代理,您无法使用 ProxyPassReverse 来调整 HTTP 重定向响应中的 URL)
关于apache - 使用 apache 进行动态主机名和端口代理,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40749739/