Working with domains

Domains are used to route requests to your service. You associate your domain names with your origin when provisioning a Fastly service so you can properly route requests to your website and ensure that others cannot serve requests to that domain. For example, you could enter www.example.com, blog.example.com, or even use wildcards such as *.example.com. You can add, edit, or remove domains from your service at any time.

Before you begin

Be sure you learn about the web interface controls and how to work with services before you start working with your domains.

Domain creation limits

  • Domains can only be associated with one service at a time. If a domain is in use by another service within your account, you can delete the domain and add it to the other service. However, if a domain is used by a service in another Fastly account, it can't be used without being delegated. In this case, contact support@fastly.com to help you delegate the domain to the correct account.
  • Services are limited to a set number of domains. We set a limit on the number of domains you can create per service by default. However, if you email support@fastly.com, we may be able to adjust this number for you by working with you to set up and fine-tune domain handling in your service.

Creating a domain for the first time

Follow the steps below to add a domain to your service for the first time:

  1. Log in to the Fastly web interface.
  2. From the Home page, select the appropriate service. You can use the search box to search by ID, name, or domain.
  3. Click the Edit configuration button and then select the option to clone the active version. The Domains page appears.

    the Create a Domain page

  4. Fill out the domain creation fields as follows:

    • In the Domain Name field, enter your domain name.
    • In the Comment field, optionally enter a comment that describes the domain.
  5. Click the Add button. Your new domain appears in the list of domains.
  6. Click the Activate button to deploy your configuration changes.
  7. If you haven't already, add a CNAME DNS record for your domain name to begin routing client traffic through Fastly services instead of directly to your origin.

Creating additional domains

Follow the steps below to add additional domains to your service:

  1. Log in to the Fastly web interface.
  2. From the Home page, select the appropriate service. You can use the search box to search by ID, name, or domain.
  3. Click the Edit configuration button and then select the option to clone the active version. The Domains page appears.

    the Domains page

  4. Click the Create domain button. The domain creation fields appear.

    the Create a Domain page

  5. Fill out the domain creation fields as follows:
    • In the Domain Name field, enter your domain name.
    • In the Comment field, optionally enter a comment that describes the domain.
  6. Click the Add button. Your new domain appears in the list of domains.
  7. Click the Activate button to deploy your configuration changes.
  8. If you haven't already, add CNAME DNS records for your domain name to begin routing client traffic through Fastly services instead of directly to your origin.

Creating a domain using the API

You can use Fastly's API to programmatically add domains to your service. To add a domain to your service, make the following API call in a terminal application:

1
$ curl -H "Fastly-Key: FASTLY_API_TOKEN" -X POST https://api.fastly.com/service/<service_id>/version/<version_id>/domain -d 'name=www.example.com'

The response will look like this:

1
2
3
4
5
6
{
  "comment": "",
  "name": "www.example.com",
  "service_id": "<service_id>",
  "version": <version_id>
}

Testing a domain

After you activate your service configuration, but before you change your DNS entries to send your domain to our servers, you can check to see how your service is pulled through our network. Testing your domain can help you identify DNS issues or problems with your Fastly configuration.

Using the web interface

To use the web interface to test your domain on Fastly before you make a final CNAME change, follow the steps below:

  1. Log in to the Fastly web interface.
  2. From the Home page, select the appropriate service. You can use the search box to search by ID, name, or domain.
  3. Click the Edit configuration button and then select the option to clone the active version. The Domains page appears.

    the Domains page

  4. Click the Test domain link next to the domain you want to test.
  5. Verify that your website appears in a new tab in your web browser.

Using command line utilities

To use command line utilities to test your domain on Fastly before you make a final CNAME change, follow the steps below:

  1. Find the IP address of a Fastly POP.
  2. Add a domain Host entry to your hosts file.
  3. Test the domain in a web browser.

Determining the IP address of a Fastly POP

Use the host, nslookup, or dig command to determine the IP address of a Fastly POP. We return different IP addresses depending on the location and state of the network making the request. As a result, the IP address you receive for any specific query may differ from the below examples but should result in the best performance for you.

Running host for your domain returns both IPv4 addresses and IPv6 addresses:

1
2
3
4
$ host www.example.com.
www.example.com.is an alias for dualstack.nonssl.global.fastly.net.
dualstack.nonssl.global.fastly.net has address 199.232.144.204
dualstack.nonssl.global.fastly.net has IPv6 address 2a04:4e42:64::204

In this example, the IPv4 address is 199.232.144.204 and the IPv6 address is 2a04:4e42:64::204.

Running nslookup for dualstack.nonssl.global.fastly.net also returns both IPv4 addresses and IPv6 addresses:

1
2
3
4
5
6
7
8
9
$ nslookup  dualstack.nonssl.global.fastly.net.
Server:         127.0.0.53
Address:        127.0.0.53#53

Non-authoritative answer:
Name:   dualstack.nonssl.global.fastly.net
Address: 199.232.144.204
Name:   dualstack.nonssl.global.fastly.net
Address: 2a04:4e42:64::204

In this example, the IPv4 address is 199.232.144.204 and the IPv6 address is 2a04:4e42:64::204.

Alternatively, you can run dig to determine the IP address, but you must specify an A query for IPv4 addresses or a AAAA query for IPv6 addresses.

Running dig for your domain with an A query returns:

1
2
3
$ dig +noall +answer -t A www.example.com.
www.example.com.        3600    IN      CNAME   dualstack.nonssl.global.fastly.net.
dualstack.nonssl.global.fastly.net. 30 IN A     199.232.144.204

The IPv4 address is 199.232.144.204

Running dig for your domain with an AAAA query returns:

1
2
3
$ dig +noall +answer -t AAAA www.example.com.
www.example.com.        3600    IN      CNAME   dualstack.nonssl.global.fastly.net.
dualstack.nonssl.global.fastly.net. 30 IN AAAA  2a04:4e42:64::204

The IPv6 address is 2a04:4e42:64::204.

Modifying your hosts file

You can temporarily add a static IP address and domain Host entry to the hosts file on your computer. Use the following anycast IPs for testing your sites served over dualstack.nonssl.global.fastly.net.

IPv4 IPv6
151.101.0.204 2a04:4e42::204
151.101.64.204 2a04:4e42:200::204
151.101.128.204 2a04:4e42:400::204
151.101.192.204 2a04:4e42:600::204

For example, if the domain you are testing is www.example.com and you are using the anycast IPv4 example 151.101.0.204, you would add this entry to the file and save the changes:

1
151.101.0.204 www.example.com

Testing your domain

Test your domain to see how Fastly pulls it through our network by restarting your browser if it's already running, and then typing your domain in the address field. You should now see the updated domain in the address field indicating requests are being sent to the Fastly POP.

Alternatively, you can test the domain using a ping command to verify that your domain is being served by a Fastly POP address. In this case, ping www.example.com would display the Fastly POP address 151.101.56.204.

Be sure to remove the Host entry from your hosts file after you make CNAME changes to point your domain to Fastly.

Deleting a domain

Follow the steps below to delete a domain from your service:

  1. On the Domains page, click the trash icon next to the domain you want to delete.
  2. Click the Confirm and delete button to confirm you want to delete your domain.
  3. Click the Activate button to deploy your configuration changes.

What's next

Learn more about working with hosts and working with health checks as you continue to refine versions of your service configurations.

Back to Top