How to do things
How to create a basic configuration
The minimal configuration to start working on Transparent Edge is to assign a backend in the VCL configuration like this:
sub vcl_recv {
set req.backend_hint = cNNN_example.backend();
}The above configuration applies to all registered websites. If you want to assign a specific backend to a particular site, you can use this configuration:
sub vcl_recv {
if (req.http.host == "www.example.com") {
set req.backend_hint = cNNN_example.backend();
}
}If you also want to cache all static content, you can enhance the configuration with this code:
sub vcl_backend_response {
if (bereq.http.host == "www.example.com") {
if (urlplus.get_extension() ~ "(?i)(jpg|jpeg|png|gif|css)") {
set beresp.http.Cache-Control = "max-age=86400";
set beresp.ttl = 86400s;
}
}
} How to assign a backend
How to cache all static content on my website
If you want to cache both in the browser and the CDN:
If you want to cache only in the CDN and not in the browser, we use the cache header max-age that affects both browsers and CDN by setting a max-age of zero, then we use the s-maxage header that only affects the CDN to rewrite the behavior only in CDN:
How to rewrite origin cache policies on my website
Example of static cache policies with exceptions and assignment if there is no origin policy
How to enable waf in detection mode
Example of WAF in Detection mode
How to add WAF exceptions
Example of WAF with exceptions
How to disable WAF for a part of my website
Exclude paths from WAF analysis
How to enable I3 to transform images to webp and avif formats
i3 - auto_webp
How to enable Bot Mitigation
First, we need to obtain a token and enable the service for the desired site in the panel in its corresponding section:
Then we configure the appropriate parameters for our site
Once this is done, we can deploy our VCL
To enable Bot mitigation:
How to remove parameters from the query string
There are several ways to remove parameters from a query string. If you want to remove a specific parameter, you can use something like this:
If you prefer, you can also use regex
If you need to remove all parameters so they cannot bypass the cache, you can use this:
How to apply a rate limit
If you want to apply a rate limit to your website based on the client's IP address. This configuration allows 20 requests in 1 second. If that rate is exceeded, the IP is blocked for 30 seconds
The rate limit can be applied in combination with a captcha or a javascript challenge, for example:
In this other example, a rate limit is enabled for the UAM so that it only applies to IPs that exceed the Rate Limit. Here, UAM will be activated for 30 seconds for the site if it receives more than 200 requests in 1 second.
How to enable UAM (Under Attack Mode) from VCL
You can enable the under attack mode (UAM) selectively from the VCL and apply it only to certain users, for example:
How to configure a website with authenticated origin in S3 (AWS)
If you have an authenticated origin in AWS in S3, you can use the following configuration to configure Transparent Edge in front of the bucket:
The TCDN-AWS-Access-Key and TCDN-AWS-Secret-Key headers are mandatory. The rest of the headers, if not provided, will use the default values which are s3 for Service and us-east-1 for Region. The bereq.http.host header is important to set it with the same value that S3 has configured to handle external calls.
How to enable midtier for a site
How to invalidate content from python
Below is a simple example in Python of how to invalidate content on our platform.
The first thing we need to do is to retrieve the token, for which we require the client_id and client_secret that can be obtained from our dashboard.
Next, once the token is obtained, we proceed to perform the invalidation:
Here is the complete script on how to implement this:
Please, be sure to replace the client_id and client_secret fields with yours.
How to apply time restrictions
f you want, you can set restrictions on a specific resource, whether it is the entire website or a specific URL within that site. For this, you can use the now function. This function returns a string in the following format:
The best way to establish a restriction based on a date is to include the current date within an HTTP header, and once inside, you can apply whatever logic you want.
Here’s a somewhat simple but effective example.
This code prevents access to that URL at 5 PM UTC. This example is quite basic, and you can definitely improve it, but it serves perfectly to explain the use of time restrictions.
Perhaps, a more elegant way to do it is by using “utils.time_format()”. For example, if we wanted to allow access from 18UTC to 20UTC in Spain, we can get the hour with %H:
Last updated
Was this helpful?
