Changing origins based on user location

Fastly allows you to change origins based on user location. The VCL looks something like this:

  # default conditions
  set req.backend = F_global;

  # Use restricted content if the user is in Asia, France or Germany
  if (geoip.continent_code == "AS" || geoip.country_code == "fr" || geoip.country_code == "de") {
    set req.backend = F_restricted_content;

So, how does this translate to the Fastly UI? First, create a new Header under the Content pane of your configuration control panel. The Type is Request and the Action is Set. Note that the priority is 10. The backend (here it's F_global should be the name of whatever your global origin server is. You can see the name if you look at your VCL).

setting a default origin via the New Header window

Now create another header almost exactly the same with two differences: it sets the backend to be your restricted origin server and the priority is higher than the previous header.

setting a restricted origin via the New Header window

Finally, attach a condition to the restricted origin header which checks the GeoIP header:

adding a restricted origin condition via the New Condition window

Back to Top