7 messages in ru.sysoev.nginxRe: use the http_perl_module to devel...
FromSent OnAttachments
焦胜强Dec 24, 2007 10:14 pm 
Changliang ChenDec 25, 2007 12:37 am 
Igor SysoevDec 25, 2007 2:25 am 
arlene chenDec 26, 2007 7:36 am 
Igor SysoevDec 26, 2007 8:51 am 
arlene chenDec 26, 2007 7:14 pm 
Igor SysoevDec 26, 2007 11:14 pm 
Actions with this message:
Paste this link in email or IM:
Paste this link in email or IM:
Atom feed for this thread
Paste this URL into your reader:
Subject:Re: use the http_perl_module to development a simple url hash moduleActions...
From:Igor Sysoev (is-G@public.gmane.org)
Date:Dec 25, 2007 2:25:54 am
List:ru.sysoev.nginx

On Tue, Dec 25, 2007 at 02:14:44PM +0800, ?????? wrote:

perl_set $backend ' sub { use Digest::MD5 (md5_hex); my $r = shift; my $uri = $r->uri; @arr = qw(192.168.1.2 192.168.1.3 192.168.1.4 192.168.1.5); $arr_num = $#arr + 1; $url = substr(md5_hex($uri), -8); $backend = $arr[hex($url) % $arr_num]; return $backend; } ';

location / { proxy_pass http://$backend$request_uri; }

The better:

upstream b1 { server 192.168.1.1; server 192.168.1.2 backup; server 192.168.1.3 backup; server 192.168.1.4 backup; }

upstream b2 { server 192.168.1.1 backup; server 192.168.1.2; server 192.168.1.3 backup; server 192.168.1.4 backup; }

perl_set $backend { ... @arr = qw(b1 b2 b3 b4);