Varnish the reverse proxy can do some pretty cool stuff. I just realized that it compiles its VCL rules into C so that they are process quite efficiently. Here’s a few examples:

Route to a different backend based upon location (i.e. url):

backend server1 {    set backend.host = "192.168.222.222";    set backend.port = "80";}

sub vcl_recv {    if (req.url ~ "^/location-url") {        set req.backend = server1;        set req.http.host = "www.example.com";    }}

Explanation: when a client requests the url “/location-url” from varnish, it “routes” the request server1, which is located at the ip address 192.168.222.222, and uses the http host name www.example.com.

Backend choice with a traditional rewrite:

backend server1 {    set backend.host = "192.168.222.222";    set backend.port = "80";}

sub vcl_recv {    if (req.url ~ "^/location-url") {        set req.backend = server1;        set req.url = regsub(req.url, "^/location-url", "/url-location");        set req.http.host = "www.example.com";    }}

Explanation: this is the same example, but the request prefix is changed from location-url to url-location. Pretty nifty, huh?

¥