Skip to content

SERA integration on Cloudflare

This configuration will only work if site DNS is in Proxy mode
Step
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:

  1. Steps for Enterprise plan customers

  2. Steps for customers with other plans

Steps for Enterprise plan customers

  1. Create an Origin rule to route requests to SERA

    1. Open Cloudflare Dashboard and Select the site on which SERA is to be configured
      Step

    2. Go to Rules then select Origin rules menu
      Step

    3. Click on Create Rule button
      Step

      1. Put Rule Name e.g.SERA routing
        Step

      2. Select Custom filter expression option

        1. Click on Edit Expression
          Step

        2. 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"))
          


          Step

          [ Maintain same expression at Origin rule as well as Transform rule ]

      3. In Then section

        1. Set Host header option to Rewrite to, and in textbox provide value sera.n7.io
          Step

        2. Set SNI option to Preserve
          Step

        3. Set DNS Record option to Override to, and in textbox provide value as sera.your.domainname.com e.g. sera.www.example.com
          Step

        4. Set Destination Port option to Preserve
          Step

      4. Place the rule at First by selecting respective option and Save it
        Step

  2. Create a DNS record for SERA

    1. Select DNS > Record menu
      Step

    2. Click on Add record
      Step

      1. Select Type as CNAME
        Step

      2. Set Name as sera
        Set Target as sera.n7.io
        Keep Proxy status switch set to Proxied
        Step

  3. Create a Transform Rule

    1. Select Rules > Transform Rules menu
      Step

    2. Select Modify Request Header tab
      Click on Create Rule button
      Step

      1. Put Rule Name e.g.SERA token setting rule
        Step

      2. Select Custom filter expression
        Put the same expression in textarea - that is set in Origin Rule
        Step

        [ Maintain same expression at Origin rule as well as Transform rule ]

      3. Select Set static
        Step

      4. Set Header name as x-nv-sera-token
        Set Value as the SERA token shared with you by N7 team
        Step


Steps for customers with other plans

  1. Create a worker with below steps

    1. Open Cloudflare Dashboard and click on Workers & Pages on the left side
      Step

    2. Click on Create Worker
      Step

    3. Give your worker a name
      Step

    4. Click on the Deploy button at the bottom right
      Step

    5. Click on Edit code
      Step

    6. Replace the example code with this code

      1. Change YOUR_TOKEN with the SERA token shared with you
      2. 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.
      3. Keep the file types which should not be sent to SERA in the SKIP_EXT array (only the pages be sent to the SERA)
        Step

    7. Click on Save and deploy
      Step

      1. If the pop-up modal shown, click on Save and deploy
        Step


  2. Map the worker to your domain with below steps

    1. Step back to the previous interface by clicking on the name of your worker on the top left
      Step

    2. Click on Settings
      Step

    3. Next to the Domains & Routes, click on +Add
      Step

    4. Select Route
      Step

    5. Type in your domain like this: example.com/ and Select the Zone where your site is
      Step

    6. Click on Add route
      Step

    7. Click on Deploy
      Step


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:
      n7TestUserAgent
      
      For mobile:
      n7TestUserAgent; Android
      
      If SERA is live, you can use these actual bot user-agent values:
      For desktop:
      Mozilla/5.0 AppleWebKit/537.36 (KHTML, like Gecko; compatible; Googlebot/2.1; +<http://www.google.com/bot.html)> Chrome/W.X.Y.Z Safari/537.36
      
      For mobile:
      Mozilla/5.0 (Linux; Android 6.0.1; Nexus 5X Build/MMB29P) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/W.X.Y.Z Mobile Safari/537.36 (compatible; Googlebot/2.1; +<http://www.google.com/bot.html)>
      
  • On go-live day, set the user-agent condition regex to actual bot user-agent values. Additionally, ensure that your condition is case-insensitive.