Forum Discussion
Nat_Thirasuttakorn
May 14, 2009Employee
Hi Sascha,
you may try this...(based on citizen_elah idea)
timing on
when RULE_INIT {
Set publications
Syntax: publicpath internalpath pool
set static::publications {
publicpath1 internalpath1 appsrv1-8020
publicpath2 internalpath2 appsrv2-8020
publicpath3 internalpath3 appsrv3-8020
publicpath4 internalpath4 appsrv4-8020
publicpath5 internalpath5 appsrv5-8020
publicpath6 internalpath6 appsrv6-8020
publicpath7 internalpath7 appsrv7-8020
publicpath8 internalpath8 appsrv8-8020
publicpath9 internalpath9 appsrv9-8020
publicpath10 internalpath10 appsrv10-8020
publicpath11 internalpath11 appsrv11-8020
publicpath12 internalpath12 appsrv12-8020
}
}
when CLIENT_ACCEPTED {
Set default publication and pool
set publication vkstintranet
pool vkstintranet
Set X-Store-Id
set STOREID Non-Store
set ip [IP::client_addr]
Setting the ip for testing purposes because dev workstation does not belong to store-network ;-)
set ip 172.20.15.32
set net_start 172.20.0.0
set net_maskbit 14
set net_mask 0.3.255.224
set net_segment_bit 5
if { [IP::addr $ip/$net_maskbit equals $net_start] }{
scan [IP::addr $ip mask $net_mask] "%d.%d.%d.%d" a b c d
set STOREID [expr ( {$a} << 24 | {$b} << 16 | {$c} << 8 | {$d} ) >> {$net_segment_bit} ]
}
set net_start 10.192.0.0
set net_maskbit 10
set net_mask 0.63.254.0
set net_segment_bit 9
if { [IP::addr $ip/$net_maskbit equals $net_start] }{
scan [IP::addr $ip mask $net_mask] "%d.%d.%d.%d" a b c d
set STOREID [expr ( {$a} << 24 | {$b} << 16 | {$c} << 8 | {$d} ) >> {$net_segment_bit} ]
}
}
when HTTP_REQUEST {
Always set X-Forwarded-For for transparency...
if {[HTTP::header exists X-Forwarded-For]} {
HTTP::header replace X-Forwarded-For [IP::client_addr]
} else {
HTTP::header insert X-Forwarded-For [IP::client_addr]
}
if {[HTTP::header exists X-Store-id] and $STOREID ne "Non-Store" } {
HTTP::header replace X-Store-Id $STOREID
} else {
HTTP::header insert X-Store-Id $STOREID
}
We're going to balance (otherwisethe request will be balanced to the default pool of the virtual server)...
set requesteduri [HTTP::uri]
foreach { publicpath publicpath srvpool } $static::publications {
if { ([HTTP::uri] starts_with "/$publicpath\/") or ([HTTP::uri] equals "/$publicpath") } {
set internalUri [regsub -nocase "/$publicpath/*" [HTTP::uri] ""]
HTTP::uri "/$publicpath/$internalUri"
set publication $publicpath
pool $srvpool
}
}
}
when HTTP_REQUEST_SEND {
log local0. "Source-IP: [IP::client_addr], Source-Port: [client_port], URI: $requesteduri, Publication: $publication, VKST: $STOREID, SelectedPoolAndNode: [LB::server]"
}
when LB_FAILED {
HTTP::respond 200 content {
Apology Page
We are sorry, but the site you are looking for is temporarily out of service
If you feel you have reached this page in error, please try again.
}
log local0. "Balancing failed. Publication: $publication"
}
not tested...
Nat