唯一想到的是使用 RewriteMap 脚本,该脚本将通过 RewriteRule 的 P 标志来决定要转到哪台机器,类似于
#!/usr/bin/perl
#This is /usr/bin/requestdistributor.pl
$| = 1; # Turn off buffering
while (<STDIN>) {
print distributeRequest($_);
}
sub distributeRequest {
my $request = shift;
#do whatever you have to do to find the proper machine for the request,
#return the complete URL with a trailing newline
}
Apache 配置文件中的“Then”
RewriteMap distributeRequests prg:/usr/bin/requestdistributor.pl
RewriteRule (.*) ${distributeRequests:$1} [P]
#Setup the reverse proxying for all machines, use the proper URLs
ProxyPassReverse / http://machine1
ProxyPassReverse / http://machine2
#and so on...
ProxyPassReverse / http://machineN
The only thing that comes to mind is to use a RewriteMap script which will decide which machine to go to, via the P flag to RewriteRule, something like
#!/usr/bin/perl
#This is /usr/bin/requestdistributor.pl
$| = 1; # Turn off buffering
while (<STDIN>) {
print distributeRequest($_);
}
sub distributeRequest {
my $request = shift;
#do whatever you have to do to find the proper machine for the request,
#return the complete URL with a trailing newline
}
Then in the Apache configuration file
RewriteMap distributeRequests prg:/usr/bin/requestdistributor.pl
RewriteRule (.*) ${distributeRequests:$1} [P]
#Setup the reverse proxying for all machines, use the proper URLs
ProxyPassReverse / http://machine1
ProxyPassReverse / http://machine2
#and so on...
ProxyPassReverse / http://machineN
Caveats: This might have some flaws as it's untested, you would have to add a new ProxyPassReverse when you add a new server (and do a graceful), and, now that I think about it, depending on the specifics of the applications you might not even need the ProxyPassReverse lines. So, test this and please tell us if it worked (or not).
发布评论
评论(1)
唯一想到的是使用 RewriteMap 脚本,该脚本将通过 RewriteRule 的 P 标志来决定要转到哪台机器,类似于
Apache 配置文件中的“Then”
警告:这可能有一些缺陷,因为它未经测试,您会当您添加新服务器(并优雅地执行)时,必须添加新的 ProxyPassReverse,而且,现在我想了一下,根据应用程序的具体情况,您甚至可能不需要 ProxyPassReverse 行。因此,请对此进行测试,然后告诉我们它是否有效(或无效)。
The only thing that comes to mind is to use a RewriteMap script which will decide which machine to go to, via the P flag to RewriteRule, something like
Then in the Apache configuration file
Caveats: This might have some flaws as it's untested, you would have to add a new ProxyPassReverse when you add a new server (and do a graceful), and, now that I think about it, depending on the specifics of the applications you might not even need the ProxyPassReverse lines. So, test this and please tell us if it worked (or not).