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

标签 apache proxy apache2

是否可以使用 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/

相关文章:

ruby-on-rails - Rails 从应用程序收到不完整的响应

node.js - 在没有代理的情况下无法使用 npm ECONNRESET 安装任何东西

ssl - Apache 2 | 1 个 IP 的 2 个域 | SSL 配置 1x 正常 1x 通配符

node.js - 让 Node.js 使用 http_proxy、https_proxy 和 no_proxy 环境变量

linux - 如何通过本地代理允许 curl ?

Apache2 未在 header 中发送 "Content-Type"

apache2 - 是否有任何 Apache 关闭 Hook 可用于清理?

apache - shell 脚本中的 CoffeeScript —— 由 Apache 运行(作为 CGI)

java - 处理由图像标记引起的过多 HTTPRequest

apache - 什么是 .htaccess 文件?