Skip to content

Instantly share code, notes, and snippets.

@wangzuo
Forked from Stanback/nginx.conf
Last active August 29, 2015 14:02
Show Gist options
  • Save wangzuo/ed3f48401d12900c2bbf to your computer and use it in GitHub Desktop.
Save wangzuo/ed3f48401d12900c2bbf to your computer and use it in GitHub Desktop.
server {
listen 80;
listen [::]:80;
server_name yourserver.com;
root /path/to/your/htdocs;
error_page 404 /404.html
index index.html;
location ~ /\. {
deny all;
}
location / {
try_files $uri @prerender;
}
location @prerender {
#proxy_set_header X-Prerender-Token YOUR_TOKEN;
set $prerender 0;
if ($http_user_agent ~* "googlebot|Feedly\/1\.0|yahoo|bingbot|baiduspider|yandex|yeti|yodaobot|gigabot|ia_archiver|facebookexternalhit|twitterbot|developers\.google\.com") {
set $prerender 1;
}
if ($args ~ "_escaped_fragment_|prerender=1") {
set $prerender 1;
}
if ($http_user_agent ~ "Prerender") {
set $prerender 0;
}
if ($prerender = 1) {
rewrite .* /$scheme://$host$request_uri? break;
#proxy_pass http://localhost:3000;
proxy_pass http://service.prerender.io;
}
if ($prerender = 0) {
rewrite .* /index.html break;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment