Skip to content

Instantly share code, notes, and snippets.

@torava
Last active April 30, 2023 12:03
Show Gist options
  • Save torava/324af0b11fafe6c5e1cc8e02121af608 to your computer and use it in GitHub Desktop.
Save torava/324af0b11fafe6c5e1cc8e02121af608 to your computer and use it in GitHub Desktop.
Prerender Wordpress NGINX HTTPS configuration
# Prerender NGINX configuration for Seravo Wordpress and HTTPS protocol
# Based on https://gist.github.com/thoop/8165802
#
# Change YOUR_TOKEN to your prerender token
# Change /path/to/your/app to the correct value
location /path/to/your/app {
proxy_set_header X-Prerender-Token YOUR_TOKEN;
set $prerender 0;
if ($http_user_agent ~* "googlebot|bingbot|yandex|baiduspider|twitterbot|facebookexternalhit|rogerbot|linkedinbot|embedly|quora link preview|showyoubot|outbrain|pinterest\/0\.|pinterestbot|slackbot|vkShare|W3C_Validator|whatsapp") {
set $prerender 1;
}
if ($args ~ "_escaped_fragment_") {
set $prerender 1;
}
# not required in this configuration
# if ($http_user_agent ~ "Prerender") {
# set $prerender 0;
# }
if ($uri ~* "\.(js|css|xml|less|png|jpg|jpeg|gif|pdf|doc|txt|ico|rss|zip|mp3|rar|exe|wmv|doc|avi|ppt|mpg|mpeg|tif|wav|mov|psd|ai|xls|mp4|m4a|swf|dat|dmg|iso|flv|m4v|torrent|ttf|woff|svg|eot)") {
set $prerender 0;
}
#resolve using Google's DNS server to force DNS resolution and prevent caching of IPs
resolver 8.8.8.8;
if ($prerender = 1) {
#setting prerender as a variable forces DNS resolution since nginx caches IPs and doesnt play well with load balancing
set $prerender "service.prerender.io";
# $scheme had to be changed to https for https protocol
rewrite .* /https://$host$request_uri? break;
proxy_pass http://$prerender;
}
try_files $uri $uri/ /index.php?$args;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment