Skip to content

Instantly share code, notes, and snippets.

@aondio
Created March 25, 2021 10:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aondio/700ae72b56d5d16d64b3d0137e473981 to your computer and use it in GitHub Desktop.
Save aondio/700ae72b56d5d16d64b3d0137e473981 to your computer and use it in GitHub Desktop.
varnishtest "shard director by req.url (default)"
server s1 {
rxreq
expect req.url == "/s1"
expect req.http.Host == "host1"
txresp -status 404 -hdr "Server: s1" -body "server1"
} -start
server s2 {
rxreq
expect req.url == "/s2"
expect req.http.Host == "host2"
txresp -hdr "Server: s2" -body "server2"
} -start
varnish v1 -vcl+backend {
import directors;
sub vcl_init {
new vd = directors.shard();
vd.add_backend(s1);
vd.add_backend(s2);
vd.reconfigure(replicas=25);
vd.backend();
}
sub vcl_recv {
set req.backend_hint = vd.backend();
}
sub vcl_deliver {
set resp.http.x-server = resp.http.Server;
}
} -start
client c1 {
txreq -url /s1 -hdr "Host: host1"
rxresp
expect resp.body == "server1"
expect resp.status == 404
txreq -url /s1 -hdr "Host: host1"
rxresp
expect resp.body == "server1"
expect resp.status == 404
txreq -url /s2 -hdr "Host: host2"
rxresp
expect resp.body == "server2"
expect resp.status == 200
} -run
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment