FASTLY_SERVICE_ID: Contains our Fastly service ID.FASTLY_API_TOKEN: Contains our Fastly API token.
Create Fastly configuration
Please define these two local environment variables before starting, using the following command lines:
--version latest.
Let’s create a dictionary which will be used as on & off switch to enable and disable the maintenance page:
maintenance_recv.vcl:
maintenance_recv.vcl VCL to Fastly:
maintenance_error.vcl like below. Note maintenance page goes within HTML
tags:
maintenance_error.vcl VCL with the maintenance page in Fastly:
Testing
From now on, we can enable and disable our maintenance page in Fastly on demand by altering the key in the dictionary. We can enable it by setting the key value to true:Enable maintenance during deployment
If we want to display the maintenance page during deployment, we can do so by adding the variables and enable followed disable the page in the deployment hooks. We can add the variables to our project like below:Note: Replace
<PROJECT_ID> and <PROD_ENVIRONMENT> with your Upsun project info.Example:<PROJECT_ID>=azertyuiop1234<PROD_ENVIRONMENT>=main
Please note:The above commands can also be applied to Platform.sh projects by replacing
upsun CLI by platform CLI in the call.Updating maintenance page
What if we want to update the maintenance page in the future? For doing so, we updatemaintenance_error.vcl with our updated maintenance page within HTML tags. We create a new
version, upload it and activate in Fastly:
Adding allowed IPs while maintenance enabled
Let’s say that we want to allow some IP ranges to allow to reach the website when the maintenance page is enabled. This is useful when we need to perform tests and other tasks during mainteance window. In order to accomplish this, we will need to create an ACL with the excluded IP ranges and exclude this list when maintenance is enabled. Create a new version to make changes:maintenance_recv.vcl VCL snippet like below:
maintenance_ips ACL even after enabling the maintenance page.
Updating maintenance ACL IPs
We can add additional IPs to the maintenance ACL in the future without cloning the version. Just add them like this:Summary
With your Fastly maintenance page configured, you can now automatically enable maintenance page in Fastly during deployments to Upsun. This setup provides:- Create Fastly configuration to enable custom maintenance page
- Automatically enable maintenance page during deployments
- Maintain custom maintenance page
Create your Upsun account today.