Multiple hostnames, multiple backends


#1

My origin consists of several servers that each require their own specific host header. Is this something that can be done in VCL?


#2

Yes. You can simply do something like:

sub vcl_recv {
#FASTLY recv
  if (req.backend == F_my_first_backend) {
    set req.http.host = "first.example.com";
  else if (req.backend == F_my_second_backend) {
    set req.http.host = "second.example.com";
  }
  ...
}

#3

Hi, Is that solution should still work properly? I have some problems with this condition and it looks like that it doesn’t check it properly for me. Is there any other good way to set http.host based on backend?

Edit:
I found a solution that works for me:

sub vcl_recv {
  set req.http.host = "first.example.com"
  if (req.http.host == "first.example.com" && randombool(1, 2)) {
    req.http.host == "second.example.com"
  }
}