SERA integration on Apache Web Server¶
Kindly follow the below examples 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¶
- Change SERA_ENDPOINT to the SERA endpoint shared with you
- Change YOUR_TOKEN to the SERA token shared with you
- Change YOUR_DOMAINS_SECRET_TOKEN to the SERA token shared with you
- Change example.com (server_name) to your actual domain
- Change /path/to/your/root to the correct value
- Keep the relevant bot user-agent regex condition mentioned below - to control the traffic being sent to SERA
LoadModule dir_module modules/mod_dir.so
LoadModule authz_core_module modules/mod_authz_core.so
LoadModule proxy_module modules/mod_proxy.so
LoadModule proxy_http_module modules/mod_proxy_http.so
LoadModule rewrite_module modules/mod_rewrite.so
LoadModule headers_module modules/mod_headers.so
LoadModule ssl_module modules/mod_ssl.so
<VirtualHost *:8080>
ServerName example.com
DocumentRoot /path/to/your/root/
<Directory "/path/to/your/root/">
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
#added for sera
RewriteEngine On
SSLProxyEngine On
#added for sera
<IfModule mod_headers.c>
RequestHeader set x-nv-sera-token "YOUR_TOKEN"
RequestHeader set x-nv-access-key "YOUR_DOMAINS_SECRET_TOKEN"
</IfModule>
#added for sera
<IfModule mod_rewrite.c>
<IfModule mod_proxy_http.c>
#USE THIS RewriteCond - DURING POC PHASE for bot User-Agent check :
RewriteCond %{HTTP_USER_AGENT} (n7TestUserAgent|google\\ page\\ speed|chrome-lighthouse|google-inspectiontool|PTST|GTmetrix) [NC,OR]
#USE THIS RewriteCond - ON GOING LIVE ON SERA for bot User-Agent check :
#RewriteCond %{HTTP_USER_AGENT} (googlebot|n7TestUserAgent|google\\ page\\ speed|chrome-lighthouse|google-inspectiontool|PTST|GTmetrix) [NC,OR]
RewriteCond %{QUERY_STRING} _escaped_fragment_
RewriteCond %{REQUEST_METHOD} ^GET$
RewriteCond %{HTTP:X-NV-APP} ^$
RewriteCond %{HTTP:X-NV-SERA-BYPASS} ^$
RewriteCond %{REQUEST_URI} .+(|\.html|\.aspx|\.php)($|\?.*) [NC]
RewriteCond %{REQUEST_URI} !.*(/static/|/_next/|/api/|/login|/logout|/account/|/wishlist/|/cart/|/checkout/|/payment/).* [NC]
RewriteCond %{QUERY_STRING) !(^|&)nsbp=[^&]+ [NC]
#USE THIS IF YOUR SITEMAP PAGE URLS DO NOT HAVE QUERYSTRING
RewriteRule (.*) SERA_ENDPOINT? [P,END]
#USE THIS IF YOUR SITEMAP PAGE URLS HAVE QUERYSTRING
RewriteRule (.*) SERA_ENDPOINT [P,END]
</IfModule>
</IfModule>
</VirtualHost>
Testing and Refinement¶
-
You can test the Apache configuration on Fiddle
-
Whitelist SERA requests at your origin to avoid any issues with indexing. Details are here
-
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.
-
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.