SERA integration on Cloudflare¶
This configuration will only work if site DNS is in Proxy mode
Else, if your pages are not cached, you can set it at origin server (Nginx, Apache, custom etc.)
Kindly follow the below steps to setup the routing of bot traffic to SERA.
Steps¶
Select the steps according to your plan:
Steps for Enterprise plan customers¶
-
Create an Origin rule to route requests to SERA¶
-
Open Cloudflare Dashboard and Select the site on which SERA is to be configured
-
Go to Rules then select Origin rules menu
-
Click on
Create Rule
button
-
Put
Rule Name
e.g.SERA routing
-
Select Custom filter expression option
-
Click on Edit Expression
-
Put below expression in textarea :
During testing phase :(http.user_agent matches r"(?i)(n7TestUserAgent|PTST|GTmetrix)" and not http.request.uri.path matches r"(?i).+\.(jpg|jpeg|png|webp|avif|gif|bmp|ico|svg|js|css|woff|woff2|ttf|eot|otf|mp3|mp4|mov|ogg|webm|wav|exe|json|txt|xml|zip|csv|pdf|php|jsp|ashx|aspx|asmx)(\?.*|$)" and not any(http.request.headers.names[*] == "x-nv-app") and not any(http.request.headers.names[*] == "X-NV-Sera-Bypass"))
For actual bots :(http.user_agent matches r"(?i)(googlebot|google page speed|chrome-lighthouse|google-inspectiontool|PTST|GTmetrix)" and not http.request.uri.path matches r"(?i).+\.(jpg|jpeg|png|webp|avif|gif|bmp|ico|svg|js|css|woff|woff2|ttf|eot|otf|mp3|mp4|mov|ogg|webm|wav|exe|json|txt|xml|zip|csv|pdf|php|jsp|ashx|aspx|asmx)(\?.*|$)" and not any(http.request.headers.names[*] == "x-nv-app") and not any(http.request.headers.names[*] == "X-NV-Sera-Bypass"))
[ Maintain same expression at Origin rule as well as Transform rule ]
-
-
In
Then
section-
Set
Host header
option toRewrite to
, and in textbox provide valuesera.n7.io
-
Set
SNI
option toPreserve
-
Set
DNS Record
option toOverride to
, and in textbox provide value assera.your.domainname.com
e.g.sera.www.example.com
-
Set
Destination Port
option toPreserve
-
-
Place
the rule atFirst
by selecting respective option andSave
it
-
-
-
Create a DNS record for SERA¶
-
Select
DNS > Record
menu
-
Click on
Add record
-
Select
Type
asCNAME
-
Set
Name
assera
SetTarget
assera.n7.io
KeepProxy status
switch set toProxied
-
-
-
Create a Transform Rule¶
-
Select
Rules > Transform Rules
menu
-
Select
Modify Request Header
tab
Click onCreate Rule
button
-
Put
Rule Name
e.g.SERA token setting rule
-
Select
Custom filter expression
Put the same expression in textarea - that is set inOrigin Rule
[ Maintain same expression at Origin rule as well as Transform rule ] -
Select
Set static
-
Set
Header name
asx-nv-sera-token
SetValue
as the SERA token shared with you by N7 team
-
-
Steps for customers with other plans¶
-
Create a worker with below steps¶
-
Open Cloudflare Dashboard and click on
Workers & Pages
on the left side
-
Click on
Create Worker
-
Give your worker a name
-
Click on the
Deploy
button at the bottom right
-
Click on
Edit code
-
Replace the example code with this code
- Change
YOUR_TOKEN
with the SERA token shared with you - Put the relevant bot user-agents in the
BOTS
array which should be routed to SERA.
Check the Testing and Refinement section for some tips. - Keep the file types which should not be sent to SERA in the
SKIP_EXT
array (only the pages be sent to the SERA)
- Change
-
Click on Save and deploy
- If the pop-up modal shown, click on Save and deploy
- If the pop-up modal shown, click on Save and deploy
-
-
Map the worker to your domain with below steps¶
-
Step back to the previous interface by clicking on the name of your worker on the top left
-
Click on
Settings
-
Next to the
Domains & Routes
, click on+Add
-
Select
Route
-
Type in your domain like this: example.com/ and Select the
Zone
where your site is
-
Click on
Add route
-
Click on
Deploy
-
Testing and Refinement¶
- 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 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:
- WPT and GTMetrix will automatically receive the response from SERA due to the routing rule set above.
- On go-live day, set the user-agent condition regex to actual bot user-agent values. Additionally, ensure that your condition is case-insensitive.