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.
Due to limitations in the DNS specification, Fastly doesn't recommend using apex or second-level domains. An example of an apex domain is example.com
rather than www.example.com
.
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.
Creating a domain for the first time
Follow the steps below to add a domain to your service for the first time:
- Log in to the Fastly web interface.
- From the Home page, select the appropriate service. You can use the search box to search by ID, name, or domain.
-
Click the Edit configuration button and then select the option to clone the active version. The Domains page appears.
-
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.
- Click the Add button. Your new domain appears in the list of domains.
- Click the Activate button to deploy your configuration changes.
- 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:
- Log in to the Fastly web interface.
- From the Home page, select the appropriate service. You can use the search box to search by ID, name, or domain.
-
Click the Edit configuration button and then select the option to clone the active version. The Domains page appears.
-
Click the Create domain button. The domain creation fields appear.
- 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.
- Click the Add button. Your new domain appears in the list of domains.
- Click the Activate button to deploy your configuration changes.
- 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>
}
Domain creation limits
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.
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:
- Log in to the Fastly web interface.
- From the Home page, select the appropriate service. You can use the search box to search by ID, name, or domain.
-
Click the Edit configuration button and then select the option to clone the active version. The Domains page appears.
- Click the Test domain link next to the domain you want to test.
- 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, you would:
- find the IP address of a Fastly pop
- add a domain Host entry to your hosts file
- test the domain in a web browser
Determining the IP address of a Fastly POP
Use the nslookup or dig command to determine the IP address of a Fastly POP.
For non-TLS requests, use nonssl.global.fastly.net
. For TLS requests, use the custom TLS CNAME record provided by Fastly support. For more information about the Fastly TLS service, see our guide on TLS service options.
For example, running nslookup for nonssl.global.fastly.net
returns:
1
2
3
4
5
6
7
$ nslookup nonssl.global.fastly.net
Server: 185.121.177.177
Address: 185.121.177.177#53
Non-authoritative answer:
Name: nonssl.global.fastly.net
Address: 151.101.56.204
Find the IP address at the bottom of the nslookup response. In this example, it's 151.101.56.204
.
Alternatively, running dig for nonssl.global.fastly.net
returns:
1
2
3
4
5
6
7
8
9
10
11
12
13
$ dig nonssl.global.fastly.net
; <<>> DiG 9.8.3-P1 <<>> nonssl.global.fastly.net
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 35146
;; flags: qr rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 0
;; QUESTION SECTION:
;nonssl.global.fastly.net. IN A
;; ANSWER SECTION:
nonssl.global.fastly.net. 30 IN A 151.101.56.204
The IP address (A record) is in the ANSWER SECTION
of the dig results: 151.101.56.204
.
Modifying your hosts file
You can temporarily add a static IP address and domain Host entry to the hosts file on your computer. For example, if the domain you are testing is www.example.com
and one of the IP addresses returned by nslookup or a dig command is 151.101.56.204
, you would add this entry to the file:
1
151.101.56.204 www.example.com
and save the changes.
On machines running macOS or Linux, your hosts file is /etc/hosts
. On Windows-based machines, it's C:\Windows\System32\Drivers\etc\hosts
.
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:
- On the Domains page, click the trash icon next to the domain you want to delete.
- Click the Confirm and delete button to confirm you want to delete your domain.
- Click the Activate button to deploy your configuration changes.
To minimize the risk of unauthorized use of your domains, we strongly recommend modifying or deleting any DNS CNAME records pointing to the Fastly hostname associated with the deleted domain. Follow the instructions on your DNS provider's website.
What's next
Learn more about working with hosts and working with health checks as you continue to refine versions of your service configurations.