-
-
Save wangzuo/ed3f48401d12900c2bbf to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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