anchor.diff:      }
   
       location / {
  -      expires off;
  -      try_files $uri $uri/ /index.html =404;
  -      <% if ENV["NGINX_DEBUG"] %>add_header X-SPA-Base-Location on;<% end %>
  -    }
  +      try_files $uri @prerender;
  +    }
  +
  +    location @prerender {
  +      proxy_set_header X-Prerender-Token <%= ENV["PRERENDER_TOKEN"] %>;
  +
  +      set $prerender 0;
  +      if ($http_user_agent ~* "baiduspider|twitterbot|facebookexternalhit|rogerbot|linkedinbot|embedly|quora link preview|showyoubot|outbrain|pinterest|slackbot|vkShare|W3C_Validator") {
  +          set $prerender 1;
  +      }
  +      if ($args ~ "_escaped_fragment_") {
  +          set $prerender 1;
  +      }
  +      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)") {
  +          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";
  +          rewrite .* /$http_x_forwarded_proto://$host$request_uri? break;
  +          proxy_pass http://$prerender;
  +      }
  +      if ($prerender = 0) {
  +          add_header "Cache-Control" "no-cache, no-store, must-revalidate";
  +          add_header "Pragma" "no-cache";
  +          add_header "Expires" "0";
  +          <% if ENV["NGINX_DEBUG"] %>add_header X-SPA-Base-Location on;<% end %>
  +          rewrite .* /index.html break;
  +      }
  +    }
  +
     }
   }
  
positive.code:       }
      <% end %>
  
      <% if ENV["BASIC_AUTH_USER"] && ENV["BASIC_AUTH_PASSWORD"] %>
        auth_basic "Restricted";
        auth_basic_user_file <%= "#{ENV["HOME"]}/config/htpasswd" %>;
  
negative.code:         proxy_set_header X-Real-IP $remote_addr;
          proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
          proxy_set_header X-NginX-Proxy true;
          proxy_set_header X-Host $host;
          proxy_ssl_session_reuse off;
          proxy_redirect off;
          <% if ENV["NGINX_DEBUG"] %>add_header X-SPA-API-Proxy on;<% end %>
        }
      <% end %>
  
      <% if ENV["API_URL"] && ENV["SITEMAP_URL"] %>
        location <%= ENV["SITEMAP_URL"] %> {
          proxy_pass <%= ENV["API_URL"][0..-2] %>;
          proxy_set_header X-Real-IP $remote_addr;
          proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
          proxy_set_header X-NginX-Proxy true;
          proxy_ssl_session_reuse off;
          proxy_redirect off;
          <% if ENV["NGINX_DEBUG"] %>add_header X-SPA-API-Proxy-Sitemap on;<% end %>
        }
      <% end %>
  
  