---
title: Changing origins based on user location
summary: null
url: >-
  https://www.fastly.com/documentation/guides/full-site-delivery/domains-and-origins/changing-origins-based-on-user-location
---

Fastly allows you to change origin servers based on the user's geographic location. This is useful when you need to serve different content to users who are in different locations. For example, you could change origin servers to serve a restricted version of your website to users in a different country.

## Using the Fastly control panel

You can use the Fastly control panel to create the headers and the condition.

### Creating the header for the default origin server

First, create a header for the default origin server to serve content to the majority of users. Follow these instructions to create the title:

1.   Log in to the [Fastly control panel](https://manage.fastly.com).

2.   From the [**Home**](https://manage.fastly.com/home) page, select the appropriate service. You can use the search box to search by ID, name, or domain.

3.   Click **Edit configuration** and then select the option to clone the active version.

4.   Click **Content**.

5. Click **Create header**.

   ![setting a default origin via the Create a header page](/img/new-header-set-default-origin.png)

6. Fill out the **Create a header** fields as follows:
   - In the **Name** field, enter the name of your header rule (for example, `Set default origin`).
   - From the **Type** menu, select **Request**, and from the **Action** menu, select **Set**.
   - In the **Destination** field, enter `backend`.
   - In the **Source** field, enter the name of the origin server you want to serve content to the majority of users (here it's `F_global`). [Preview the VCL](https://www.fastly.com/documentation/guides/full-site-delivery/fastly-vcl/working-with-custom-vcl#previewing-vcl-before-activation) to find the name of the origin server.
   - From the **Ignore if set** menu, select **No**.
   - In the **Priority** field, enter `10`.

7. Click **Create**.

### Creating the header for the restricted origin server

Now, create a header for the restricted origin server to serve content to the users residing in the countries specified in the condition. Follow these instructions to create the title:

1.   Click **Content**.

2. Click **Create header**.

   ![setting a restricted origin via the Create a new header page](/img/new-header-set-restricted-origin.png)

3. Fill out the **Create a header** fields as follows:
   - In the **Name** field, enter the name of your header rule (for example, `Set restricted origin`).
   - From the **Type** menu, select **Request**, and from the **Action** menu, select **Set**.
   - In the **Destination** field, enter `backend`.
   - In the **Source** field, enter the name of the restricted origin server you want to serve content to the users residing in the countries specified in the condition (here it's `F_restricted_content`). [Preview the VCL](https://www.fastly.com/documentation/guides/full-site-delivery/fastly-vcl/working-with-custom-vcl#previewing-vcl-before-activation) to find the name of the origin server.
   - From the **Ignore if set** menu, select **No**.
   - In the **Priority** field, enter `11`.

4. Click **Create**.

### Creating a condition for the restricted origin header

Finally, create a condition for the restricted origin header. The condition checks the [geolocation header](https://www.fastly.com/documentation/reference/vcl/variables/geolocation/). If the user's geolocation matches a location specified in the condition, Fastly uses the restricted origin server. Follow these instructions to create the condition:

1.   Click **Content**.

2. In the Headers section, click **Attach a condition** next to the **Set restricted origin** header.

   ![adding a restricted origin condition via the Create a new request condition window](/img/new-condition-from-restricted-location.png)

3. Fill out the **Create a new request condition** fields as follows:
   - In the **Name** field, enter a descriptive name for the new condition (for example, `From Restricted Location`).
   - In the **Apply if** field, enter a request condition. For example, to send all users in Asia and Europe to the restricted origin server, enter `client.geo.continent_code == "AS" || client.geo.continent_code == "EU"`. See [Geolocation-related VCL features](https://www.fastly.com/documentation/reference/vcl/variables/geolocation/) for more information.

4. Click **Save and apply to**.

5.   From the **Activate** menu, select **Activate on Production** to deploy your configuration changes.

## Using custom VCL

If you'd prefer not to use the Fastly control panel, you can use custom VCL to configure your service to change origin servers based on the user's geographic location. Use the following VCL as a starting point:

```vcl
  # default conditions
  set req.backend = F_global;

  # Use restricted content if the user is in Asia, France or Germany
  if (client.geo.continent_code == "AS" || client.geo.country_code == "FR" || client.geo.country_code == "DE") {
    set req.backend = F_restricted_content;
  }
```

## Related content

- [Use regionally distributed origin servers](https://www.fastly.com/documentation/solutions/examples/use-regionally-distributed-origin-servers/)
