Skip to content

Instantly share code, notes, and snippets.

@MWers
Forked from Stanback/nginx.conf
Created November 7, 2013 18:39
Show Gist options
  • Save MWers/7359676 to your computer and use it in GitHub Desktop.
Save MWers/7359676 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 Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
#proxy_intercept_errors on;
set $prerender 0;
if ($http_user_agent ~* "googlebot|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://prerender.herokuapp.com;
}
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