SERA integration on Nginx¶
This configuration will only work if you have set proxy_ssl_server_name on;
in server block
Kindly follow the below examples to setup the routing of bot traffic to SERA.
- Change YOUR_TOKEN the SERA token shared with you
- Change example.com for 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
worker_processes auto;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;
map_hash_bucket_size 1024;
map $http_user_agent $sera_ua_check { #added for sera
default 0;
"~*sera" 0;
"~(^|&)_escaped_fragment_=" 0;
#USE THIS - DURING POC PHASE for bot User-Agent regex check :
"~*n7TestUserAgent|PTST|GTmetrix" 1;
#USE THIS - ON GOING LIVE ON for bot SERA User-Agent regex check :
"~*googlebot|google\ page\ speed|chrome-lighthouse|google-inspectiontool|PTST|GTmetrix" 1;
}
map $request_uri $sera_ext_check { #added for sera
default sera_ua_check;
"~*\.(ai|ashx|asmx|aspx|avi|avif|bmp|css|csv|dat|dmg|doc|eot|exe|flv|gif|ico|iso|jpeg|jpg|js|json|jsp|less|m4a|m4v|mov|mp3|mp4|mpeg|mpg|ogg|otf|pdf|php|png|ppt|psd|rar|rss|svg|swf|tif|torrent|tf|txt|wav|webm|webp|wmv|woff|woff2|xls|xml|zip)" 0;
}
map $request_uri $sera_url_check { #added for sera
default sera_ext_check;
"~*(/api/|/cart/|/checkout/|/wishlist/|/profile/)" 0;
}
map $http_x_nv_app $sera_app_check { #added for sera
default $sera_url_check;
"~.+" 0;
}
map $http_x_nv_sera_bypass $sera_final_check { #added for sera
default $sera_app_check;
"~.+" 0;
}
server {
listen 80;
server_name example.com;
proxy_ssl_server_name on;
root /path/to/your/root;
location / {
if (sera_final_check = 1) { #added for sera
rewrite (.*) /sera_target last;
}
#existing configuration
#try_files $uri /index.html = 404;
}
location /sera_target { #added for sera
resolver 8.8.8.8 1.1.1.1;
set $sera_host sera.n7.io;
proxy_set_header host $sera_host;
proxy_set_header x-nv-sera-token YOUR_TOKEN;
proxy_pass https://$sera_host;
rewrite .* $request_uri? break;
}
}
}
Testing and Refinement¶
- You can test the Nginx 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 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.