Dynamic hostname and port proxying with apache

自古美人都是妖i 提交于 2021-01-27 20:10:25

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!