Working with custom VCL
- English
- 日本語
Fastly allows you create your own Varnish Configuration Language (VCL) files with specialized configurations. By uploading custom VCL files, you can use custom VCL and Fastly VCL together at the same time. Any time you upload VCL files, you can preview the VCL prior to activating a new version of your service. Keep in mind that your custom VCL always takes precedence over VCL generated by Fastly.
For guidance on writing VCL code, including common use cases and best practices, check out our Writing VCL code guide.
IMPORTANT:
Personal data should not be incorporated into VCL. Our Compliance and Law FAQ describes in detail how Fastly handles personal data privacy.
Creating a custom VCL file
To create a custom VCL file, follow these steps. You'll use Fastly's VCL boilerplate when creating new files to prevent errors from duplicate definitions, conflicts, and version-specific metadata.
NOTE: We don't provide embedded C access in custom VCL because inline C code on shared infrastructure creates serious security vulnerabilities, including potential data access across customer boundaries and system instability.
Log in to the Fastly control panel.
From the Home page, 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 VCL.
- Click Custom VCL.
- Click Upload Custom VCL.
- In the Name field, enter an appropriate name.
- In the VCL editor, click Insert boilerplate code.
- Edit the boilerplate as needed with your custom VCL. For help writing your VCL logic, check out our Writing VCL code guide.
- Click Add. The custom VCL file appears in the list of VCL files on the Custom VCL tab. If this is your first custom VCL file, it will automatically be labeled as your main VCL file.
NOTE: You can split your custom VCL into several files to make them easier to maintain. Our guidance on [using multiple VCL files](#using-multiple-custom-vcl-configuration files) describes how to do this in detail.
Editing a custom VCL file
To edit an existing VCL file, follow these instructions:
Log in to the Fastly control panel.
From the Home page, 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 VCL.
- Click Custom VCL.
- From the list of custom VCL files, select the one you want to edit.
- Click Edit.
- (Optional) In the Name field, enter a new name for the custom VCL file.
- In the VCL editor area, make the necessary code changes to your file. For help writing your VCL logic, check out our Writing VCL code guide.
- Click Save to update the VCL file in the Fastly application.
Click Activate to deploy your configuration changes.
Downloading a VCL file
To download an existing VCL file, including your complete VCL, follow these instructions:
Log in to the Fastly control panel.
From the Home page, 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 VCL.
- Click Custom VCL.
- Click the three dots to the right of the file name for the file you want to download.
- Select Download from the menu that appears.
Uploading a custom VCL file
Follow these instructions to upload a custom VCL file:
Log in to the Fastly control panel.
From the Home page, 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 VCL.
- Click Custom VCL.
- Click Upload custom VCL file.
- In the Name field, enter the name of the VCL file. If you're using multiple VCL files, this name must match the name you use to reference the custom file in your main VCL. Our guidance on using multiple VCL files describes this in more detail.
- Click Upload config file and select a file to upload.
- Click Open. The VCL file appears with a confirmation message "Filename accepted."
- Click Add.
Click Activate to deploy your configuration changes.
Using multiple custom VCL configuration files
To make your VCL configurations easier to maintain, you can split your VCL file into multiple files, each of which will be accessed by a main VCL file. This allows you to separate out chunks of logic (for example, logic that has a specific purpose or that might change frequently) into as many separate files as makes sense.
Setting up multiple VCL files
To use multiple custom VCL files, follow these steps:
Start by isolating a portion of VCL and placing it in a separate file. The name of the file doesn't matter, nor does the file extension. A
foo.vcl
file will work just as well as abar.txt
file.Upload the file to include it in your Varnish configurations and give it a unique name when you fill out the Name field at the time of upload (for example, you could call it
Included VCL
). The uploaded file will appear in the Varnish Configurations area along with your main VCL file.In the main VCL file, enter the name of the included VCL file on a separate line. For example, your Included VCL file would get added to the main VCL file in a single line like this:
include "Included VCL";Continue uploading VCL files and then including them in your main VCL using the syntax
include "<VCL FILE>";
, where<VCL FILE>
exactly matches the name you entered in the Name field of your custom VCL.Decide if you want to change which file serves as your main VCL file.
Click Activate to deploy your configuration changes.
HINT: Our guide to manually creating access control lists demonstrates a common example of using included VCL.
Changing which file serves as your main VCL file
When you use multiple VCL files, you can change which one serves as the main VCL file by following these steps:
Log in to the Fastly control panel.
From the Home page, 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 VCL.
- Click Custom VCL.
- Click the three dots to the right of the file name for the file you want to be your main VCL file.
- Select Set as main config from the menu that appears.
Click Activate to deploy your configuration changes.
Deleting a custom VCL file
Log in to the Fastly control panel.
From the Home page, 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 VCL.
- Click Custom VCL.
- Click the three dots to the right of the file name for the file you want to delete.
- Select Delete from the menu that appears.
- Confirm you want to delete the custom VCL file by clicking Delete.
Previewing VCL before activation
Follow these instructions to preview VCL prior to activating a service version:
Log in to the Fastly control panel.
From the Home page, select the appropriate service. You can use the search box to search by ID, name, or domain.
- Click Show VCL. The VCL preview page appears.
HINT: Need more space on the screen to view a service's custom VCL or complete VCL? Click the Fullscreen link.
Reviewing VCL errors
If there are syntax errors or other issues in your custom VCL, Fastly will identify them when you try to activate your service version. To review and fix VCL errors:
Log in to the Fastly control panel.
From the Home page, 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 VCL.
- Click the warning indicator above the VCL tabs. A list of errors, their descriptions, and a link to their locations in your VCL files appear.
- Click the error you want to review. Your complete VCL file appears with the error line highlighted.
- Fix the error with the appropriate edits. For help with common use cases, check out our guide to writing VCL code. Our VCL reference provides details about VCL syntax.
Click Activate to deploy your configuration changes.