VCL services
VCL services offer an efficient mechanism to manage and control traffic to your domains, powered by Fastly's variant of the Varnish Configuration Language (VCL). The code you run on VCL services is compiled by Fastly, which means that in addition to uploading VCL code via our API or CLI, you can also write it directly into our web interface or enable high level features that will generate VCL code for you.
Getting started
You must create a Fastly account if you don't already have one.
Create a service
Create a new, empty VCL service.
- Web interface
- CLI
- Log in to manage.fastly.com.
- From the Create service menu, select
CDN
.
Fastly services are versioned. The first version of your service, created when the service itself is created, is version 1.
Add a domain and a backend
VCL services require a domain before you can activate them. The domain is the hostname that you want to point to Fastly.
HINT: For now, it's easier to use a Fastly-assigned domain. We'll get to using a custom domain later.
For VCL services, Fastly provides automatic TLS and routing for hostnames of the form <something>.global.ssl.fastly.net
. It's a good idea to use something related to the domain you plan to eventually use, e.g. example-com.global.ssl.fastly.net
.
- Web interface
- CLI
At the end of the last step, you were on the service configuration page of a new VCL service, and the Domains section is active by default.
- If it's visible, click the Create domain button. This button is only displayed if you already have domains configured.
- Enter a hostname in the form (e.g.,
<something>.global.ssl.fastly.net
). - Click Add.
If you add multiple domains, all of the domains will be associated with the service, and traffic to any of them will be processed in the same way.
Now create a backend. The backend is the location to which Fastly should forward requests, and it can be an IP address or hostname.
- Web interface
- CLI
- Click Origins.
- If you don't see the Hosts field, click the Create a host button.
- In Hosts, enter the hostname or IP address of your origin server.
- Click Add to add your host.
- Optionally click the pencil icon next to the host to edit more detailed settings:
- In the Name field, enter a derivative of the hostname (
example_com
) or the purpose of the backend (primary_content
), using only lowercase alphanumeric characters and underscores. - In the Override host field, enter the same hostname as the backend's hostname.
- In the Name field, enter a derivative of the hostname (
If you add multiple backends, only the first will be used, unless you configure conditions, load balancing, or failover, or explicitly change the backend by setting the value of req.backend
in VCL. Learn more about using backends with your Fastly service.
Activate your service
The first version of your service, which you have been editing to add the domain and backend, is in draft mode. That allows you to make changes to the service configuration, and then apply the changed configuration in one operation. It also allows you to roll back to any earlier version of your configuration if you make a mistake or discover a problem.
It's time to activate the first version of the service:
- Web interface
- CLI
Click the Activate button.
Test the service
After activation, use the fastly-assigned test domain you attached to your service earlier to send a request to Fastly:
$ curl -si "https://example-com.global.ssl.fastly.net/"HTTP/1.1 200 OKContent-Type: text/html; charset=utf-8Date: Thu, 28 May 2020 17:48:38 GMTAge: 0X-Served-By: cache-lon4266-LONX-Cache: MISSX-Cache-Hits: 0
...content...
The X-Served-By
header shows you which Fastly POP handled your request, and the X-Cache
header tells you that it was a cache miss (i.e., the request was forwarded to the backend).
Add your own domain
Now that you have a working service, you may want to assign a domain name to it. We have a lot of TLS options. As a starting point, it's a good idea to create a TLS Subscription so that Fastly will generate a certificate for you.
Going further
Now that you have a working VCL service up and running, check out using VCL to find out how to start writing your own edge processing logic. When you're ready to upload VCL to your service, clone the current service version, then upload new VCL and activate a new version.
You can find hundreds of examples of VCL solutions in our solutions library, from simple ones that add geolocation data to your request to complex solutions like doing A/B testing at the edge,