• Download source here
  • Run $ npm install to install
  • Edit index.js file and change your default port
  • Use pm2 to start prerender server. Like $ pm2 start index.js –name=”pre-render-server”
  • Modify your nginx config (for web only) to content below (you can see all content in the README.MD file)

server {

   listen 443;

 ssl    on;

 ssl_certificate    /path/to/fullchain.pem;

 ssl_certificate_key    /path/to/privkey.pem;

 

 server_name app;

 

 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;

 }

 

 location / {

   root /var/www/app/web;

   index index.html index.htm;

 

   if ($prerender = 1) {

     #setting prerender as a variable forces DNS resolution since nginx caches IPs and doesnt play well with load balancing

     #resolve using Google’s DNS server to force DNS resolution and prevent caching of IPs

     # resolver 8.8.8.8;

     rewrite .* /$scheme://$host$request_uri? break;

     proxy_pass http://localhost:8081;

   }

 

   try_files $uri $uri/ /index.html?$query_string;

 }

}

Leave a Reply

Your email address will not be published. Required fields are marked *