SERA integration on Fastly¶
Kindly follow the below steps to setup the routing of bot traffic to SERA.
Prerequisites¶
- All your page requests must get intercepted by below SERA routing rule
- Please check your routing, caching and cache-variation policies for that
- If caching is enabled, Users and Bots should have a separate cache-variations configured. This is to not serve the SERA's bot-optimized-content to users.
Steps¶
Kindly follow the below examples to setup the routing of bot traffic to SERA.
- Change SERA_ENDPOINT to the SERA endpoint shared with you
- Change YOUR_TOKEN to the SERA token shared with you
- Keep the relevant bot user-agent regex condition mentioned below - to control the traffic being sent to SERA
Create a backend in the Fastly service¶
- Clone the currently active version and create a backend for SERA.
- You can use the following example code snippet for creating a SERA backend in your Fastly service.
backend o_s {
.always_use_host_header = true;
.between_bytes_timeout = 5s;
.connect_timeout = 10s;
.dynamic = true;
.first_byte_timeout = 45s;
.host = "SERA_ENDPOINT";
.host_header = "SERA_ENDPOINT";
.port = "443";
.ssl = true;
.ssl_check_cert = never;
.ssl_sni_hostname = "SERA_ENDPOINT";
}
Route Crawler requests to SERA¶
- Use the same draft intercept and route the crawler requests to SERA.
- Please refer to the following VCL snippet to intercept and route the required crawler requests to SERA in vcl_recv subroutine.
- You need to add the following snippet in addition to your previous configuration(if any).
- Note: Do not replace vcl_recv subroutine as it is if you have any existing configuration.
sub vcl_recv {
# only send PAGE requests to SERA
if (req.method == "GET"
&& req.url.ext !~ "^(|html|php|aspx)$"
&& req.url !~ ".*\?(.*&)*nsbp=.*"
&& req.url !~ ".*\?(.*)/(api|login|logout|account|wishlist|cart|checkout|payment).*"
&& !req.http.x-nv-app
&& !req.http.x-nv-sera-bypass) {
# DURING POC PHASE - USE THIS if condition for bot User-Agent check :
if (req.http.User-Agent ~ "(?i)(n7TestUserAgent|google\ page\ speed|chrome-lighthouse|google-inspectiontool|PTST|GTmetrix)") {
# ON GOING LIVE ON SERA - USE THIS if condition for bot User-Agent check :
# if (req.http.User-Agent ~ "(?i)(googlebot|n7TestUserAgent|google\ page\ speed|chrome-lighthouse|google-inspectiontool|PTST|GTmetrix)") {
set req.http.X-NV-Sera-Token = {YOUR_TOKEN};
set req.http.X-NV-Access-Key = {YOUR_N7_ACCESS_KEY};
set req.backend = F_o_s;
return(lookup);
}
}
# existing configuration
}
Testing and Refinement¶
-
You can test the Fastly configuration on Fiddle
-
Keep refining the logic by adjusting user-agent list, and SERA exclusion-patterns as needed.
-
Test thoroughly:
-
WPT and GTMetrix will automatically receive the response from SERA due to the routing rule set above.
- Steps to validate page using WPT
-
To check the SERA rendered page on browser, you can use DevTools > Network conditions facility, or some browser extension (like Simple modify headers) to manipulate the browser user-agent. If in testing phase, use these user-agent values: For desktop:
For mobile: If SERA is live, you can use these actual bot user-agent values: For desktop: For mobile:
-
-
On go-live day, set the user-agent condition regex to actual bot user-agent values. Additionally, ensure that your condition is case-insensitive.
-
Whitelist SERA requests at your origin to avoid any issues with indexing. Details are here
-
After go-live, in any dashboards created for monitoring the "actual user traffic" e.g. Google analytics, exclude the requests with user-agent string containing word "Nitrogen SERA" to get correct understanding about user-traffic.