我正在运行一个转发代理,我想使用ProxyRemote将某些请求转发到不同的代理服务器。 哪个请求去哪个服务器取决于许多因素(时间,负载,url,主机,用户…),并且必须由外部程序计算。
该过程目前通过向请求url的主机添加后缀,然后通过ProxyRemoteMatch指令进行匹配。 这是通过传递URL到一个重写映射。
这工作很好,但有贸易,我必须在configuration和DNS中定义EVERY服务器。
这是一个工作的例子:
RewriteEngine on // define an external program that contains the logic where which request should be routed to RewriteMap balancemap prg:/home/mysite/balancemap.php <ProxyMatch "http://.*"> RewriteEngine on // if the route has not yet been set by suffix proxy pattern, pass the request uri and user to the mapping program and store it in an environment variable // for example http://google.com will be rewritten to something like http://google.com.5.server.mysite.com - which means it should be routed over server number 5 RewriteCond %{HTTP_HOST} !\.([0-9]+)\.server\.mysite\.com$ RewriteCond ${balancemap:%{REQUEST_URI}#%{REMOTE_USER}} .* RewriteRule .* - [E=BALANCEDURL:%0] // if a new url has been calculated, rewrite to it RewriteCond %{ENV:BALANCEDURL} .+ RewriteRule .* %{ENV:BALANCEDURL} [P] </ProxyMatch> // now comes the long ist of servers.... // every subdomain is mapped to the correct ip address in internal dns system ProxyRemoteMatch .*\.1\.server\.mysite\.com.* http://1.server.mysite.com:80 ProxyRemoteMatch .*\.2\.server\.mysite\.com.* http://2.server.mysite.com:80 ProxyRemoteMatch .*\.3\.server\.mysite\.com.* http://3.server.mysite.com:80 ProxyRemoteMatch .*\.4\.server\.mysite\.com.* http://4.server.mysite.com:80 ... and so on
基本上我希望是一个ProxyRemoteDirective,支持像这样的反向引用:
ProxyRemoteMatch .*\.(\d+)\.server\.mysite\.com.* http://$1.server.mysite.com:80
或者我甚至可以给这个IP:
ProxyRemoteMatch .*\.(\d+)\.(\d+)\.(\d+)\.(\d+)/.* http://$1.$2.$3.$4:80
有关您的信息:主机名称的自定义部分ist剥离转发代理服务器上的url。 我也想摆脱这一点,通过传递的url是!
所以如果ProxyRemoteMatch指令的第二个参数会插入环境variables,它将看起来像这样:
// now our map just returns the ip of the correct remote server RewriteCond ${balancemap:%{REQUEST_URI}#%{REMOTE_USER}} .* RewriteRule .* - [E=REMOVESERVER:%0] ProxyRemoteMatch .* http://%{ENV:REMOVESERVER}:80
这将是最棒的。
但不幸的是没有上述的作品。
我花了一段时间才弄清当前的系统,现在我有大约200行的ProxyRemoteMatch指令(200个远程服务器)。 但保持一切与DNS和所有东西都是痛苦的屁股。
Maby你也可以推荐一个替代品? 也许同样的行为可以很容易地与其他代理服务器软件? 可能是Nginx? 乌贼?
所以任何想法都欢迎!
仅供参考,这是一个商业项目,但我自己运行,现在没有真正的利润。 我打算开放源代码,但一旦稳定,就用自己的服务运行。
我想我也会尽快提出这个问题的赏金。
鉴于下面的循环(perl,但语言'yyyyy'会做)
foreach my $i (1..200) { print "ProxyRemoteMatch .*\\.$i\\.server\\.mysite\\.com.* http://$1.server.mysite.com:80\n"; }
打印所有长和重复的configuration部分,为什么打扰? 你可以用这样的一行来维护整个shebang。 你甚至可以使用Include来完全清除configuration文件。 在图片中引入“make”可能会让您在添加/删除服务器时自动运行它。