Forum Discussion
Loadbalance Web server
Here is an iRule to inject/manage cache control headers:
when HTTP_REQUEST {
switch -glob [string tolower [HTTP::uri]] {
"*.jpg" -
"*.png" -
"*.gif" {
set uncache 1
HTTP::header remove "If-Modified-Since"
HTTP::header remove "If-None-Match"
}
}
}
when HTTP_RESPONSE {
if { [info exists uncache] } {
unset uncache
HTTP::header remove "Etag"
HTTP::header insert "Cache-Control" "no-cache"
}
}
This is only going to affect requests for specific image types. If you're load balancing servers with different content, you don't necessarily want to force a TCP session closure after each request. For example, let's say you load balance to a server that makes an img src reference to "/image1.png". You serve the page and then close the connection. When the browser makes its request for "/image.png", it's going to initiate a new load balancing decision, and potentially land on a server that does not have this image. The above will make sure that like image names aren't cached across requests, but you'll still probably want to leave the TCP session alone (which usually defaults to about 5 seconds). If you refresh your browser every 6 seconds, you should see the images swap. Alternately you can adjust both the TCP and HTTP Keep-Alive time out values, but do so with care.
Help guide the future of your DevCentral Community!
What tools do you use to collaborate? (1min - anonymous)Recent Discussions
Related Content
* Getting Started on DevCentral
* Community Guidelines
* Community Terms of Use / EULA
* Community Ranking Explained
* Community Resources
* Contact the DevCentral Team
* Update MFA on account.f5.com