Core concepts
Start with the basics and learn how Fastly lets you take advantage of the modern internet.
Regardless of whether you are using Compute or VCL, your Fastly services need domains (to receive traffic), backends (to forward traffic onward), TLS (to secure connections between Fastly and end users), and DNS (to point your domains to Fastly).
Setting up a backend
Backends are servers you can make requests to from Fastly, usually your own servers, and are typically defined as part of your service configuration. To create a backend:
- Web interface
- CLI
- Fastly VCL
- Log in to manage.fastly.com and select the appropriate service. You can use the search box to search by ID, name, or domain.
- Click Edit configuration and then select the option to clone the active version.
- Click Origins.
- If you don't see the Hosts field, click Create a host.
- In the Hosts field, enter the hostname or IP address of your origin server.
- Click Add to add your host.
- (Optional) Click the pencil icon next to the host to edit more detailed settings:
- In Name, enter a derivative of the hostname (
example_com) or the purpose of the backend (primary_content), using only lowercase alphanumeric characters and underscores. - In Override host, enter the same hostname as the backend's hostname.
- In Name, enter a derivative of the hostname (
Use fastly backend create in the Fastly CLI:
$ fastly backend create --version=latest --autoclone --name=example_com --address=example.comSUCCESS: Created backend example_com (service 21eRnruIBLL4BwkKdUU11Y version 3)
</Panel><Panel id="api" label="API">
Use the [Backends API](/reference/api/services/backend):```term$ curl -i -X POST "https://api.fastly.com/service/SU1Z0isxPaozGVKXdv0eY/version/1/backend" -H "Fastly-Key: YOUR_FASTLY_TOKEN" -H "Content-Type: application/x-www-form-urlencoded" -H "Accept: application/json" -d "address=example.com&name=example_com&override_host=example.com&ssl_sni_hostname=example.com&ssl_cert_hostname=example.com"In CDN services, backends can be created using VCL code in custom VCL files or 'init' VCL snippets:
123456789101112backend example_com { .dynamic = true; .share_key = "YOUR_SERVICE_ID"; .host = "example.com"; .port = "443"; .ssl = true; .ssl_cert_hostname = "example.com"; .ssl_check_cert = always; .ssl_sni_hostname = "example.com"; .host_header = "example.com"; .always_use_host_header = true;}For full details refer to the backend declaration in the VCL reference.
Compute services also support defining backends dynamically (at runtime). For more details and other things to consider when creating backends refer to integrating with backend technologies.
Setting up a domain
Domains point traffic to your Fastly services. To allow clients to connect to Fastly using your domain, Fastly must be able to establish a secure connection on your behalf. We have many TLS service options available (for full details consult routing traffic to Fastly), but if you are happy to use a default TLS configuration and have Fastly issue certificates on your behalf, create a TLS subscription for your domain.
To do this, clone the active version of your service, add the domain, and activate the new version. Next, add a TLS subscription for that domain to your account. Finally, configure your DNS provider or domain registrar to verify your domain ownership.
- Web interface
- CLI
- Log in to manage.fastly.com and select the appropriate service. You can use the search box to search by ID, name, or domain.
- Click Edit configuration and then select the option to clone the active version.
- If you already have domains, click Create domain.
- Enter a hostname or IP address.
- Click Add.
- From the Activate menu, select Activate on Production to save and activate the new version of your service.
- Click Secure in the top navigation bar.
- Click Manage certificates. The TLS domains page appears displaying any domains for which TLS has been or can be activated.
- Click Get started if it is available. Otherwise, click the Secure another domain button and select Use certificates Fastly obtains for you.
- In Domain, enter the domain name and click Add. If your account has access to multiple certification authorities or TLS configurations, learn more about your options.
- Click Submit.
- Note the CNAME record required for verification.
Run these commands while in the root directory of your project:
# Add the domain to a new draft version of your service$ fastly domain create --name=fastly.com --version=latest --autocloneSUCCESS: Created domain fastly.com (service PS1Z4isxPaoZGVKVdv0eY version 3)
# Activate the new version$ fastly service-version activate --version=latestSUCCESS: Activated service PS1Z4isxPaoZGVKVdv0eY version 3
# Create a TLS subscription for the domain in your Fastly account$ fastly tls-subscription create --domain=fastly.comSUCCESS: Created TLS Subscription 'XfHLv310UUpJoEbsaJtY1Q' (Authority: lets-encrypt, Common Name: fastly.com)
# Display the subscription's challenge activation record$ fastly tls-subscription describe --id='XfHLv310UUpJoEbsaJtY1Q' --include tls_authorizations --json{ "Authorizations": [{ "Challenges": [ { "RecordName": "_acme-challenge.fastly.com", "RecordType": "CNAME", "Values": [ "lxpqwv66ixn7e3bn4r.fastly-validations.com" ] } ]} ], "CertificateAuthority": "lets-encrypt", "Configuration": { "ID": "3TIFxmdUnUx6hOVYMHhlPg", "Type": "" }, "Domains": [{ "ID": "fastly.com" }], "ID": "XfHLv310UUpJoEbsaJtY1Q", "State": "pending"} The final command will produce a JSON object. The CNAME for the verification challenge is the record starting with _acme-challenge. Also note down the TLS Configuration ID, which is under Configuration.ID.
You now have the ACME challenge CNAME record required to prove that you own the domain. Log in to your DNS provider or domain registrar and configure the required record. For example:
- Record type:
CNAME - Subdomain:
_acme-challenge - Target host:
lxpqwv66ixn7e3bn4r.fastly-validations.com
Fastly will periodically check for these records to be published. When verification is complete, the status of the subscription will change from "Pending verification" to "Activated".
Once the domain is activated, you can retrieve the DNS records that point traffic on your domain to Fastly:
- Web interface
- CLI
- Log in to manage.fastly.com.
- Click Secure in the top navigation bar.
- Click Manage certificates.
- Find the domain you want and click View details.
- Note the CNAME, A, and AAAA records.
Using the TLS configuration ID that you noted down from the previous step:
$ fastly tls-config describe --id="XLqo5lsrEb2FcYlE4Etpq2" --include dns_records --json{ "ID": "XLqo5lsrEb2FcYlE4Etpq2", "DNSRecords": [ { "ID": "151.101.2.132", "RecordType": "A", "Region": "global" }, { "ID": "151.101.66.132", "RecordType": "A", "Region": "global" }, { "ID": "151.101.130.132", "RecordType": "A", "Region": "global" }, { "ID": "151.101.194.132", "RecordType": "A", "Region": "global" }, { "ID": "j.sni.global.fastly.net", "RecordType": "CNAME", "Region": "global" } ], "HTTPProtocols": [ "http/1.1", "http/2" ], "TLSProtocols": [ "1.2", "1.3" ]}Note the CNAME, A and AAAA records.
Back in your DNS provider or domain registrar, add the DNS records to point your domain to Fastly.
- If the domain is a subdomain, such as
www.example.comormy-website.herokuapp.com, use the CNAME records. - If the domain is an apex, such as
example.comorexample.co.uk, use the A and AAAA records.
HINT: Use subdomains if possible. We can do more resilient, faster routing if you use a CNAME with a subdomain instead of using an apex domain. Find out more about routing traffic to Fastly.
Once these records are configured, you should be able to visit your Fastly-hosted website by entering your new domain into the browser (you may need to wait some time for the DNS records to propagate across the Internet).
Advanced concepts
Read more about all Fastly's features and technical principles:
- Cache interfaces
- Compression
- Errors
- Geolocation
- Health checks
- Load balancing
- Rate limiting
- Real time push messaging
- Redundancy and failover
- Routing traffic to Fastly
- Service types
- Shielding
Content served through Fastly is cached based on freshness rules you define in Cache-Control headers or in the configuration of your Fastly service. Within each Point of Presence (POP), many servers act together in a cluster to provide a single large, efficient pool of cache storage.
Fastly POPs operate independently of each other and forward requests to your origin server if a request cannot be satisfied in that POP. Similar requests arriving at the same time in the same POP are collapsed and only one is forwarded. However, using shielding you can opt to focus all origin requests from across the Fastly network to a single Fastly POP, greatly reducing origin traffic, especially if your customers are spread globally.
Our purging system allows objects previously cached by Fastly to be marked stale or invalidated entirely. Globally purging an object takes around 150ms.