{"id":1553,"date":"2013-07-18T14:39:58","date_gmt":"2013-07-18T18:39:58","guid":{"rendered":"http:\/\/cd34.com\/blog\/?p=1553"},"modified":"2013-07-18T14:40:57","modified_gmt":"2013-07-18T18:40:57","slug":"varnish-and-node-js","status":"publish","type":"post","link":"https:\/\/cd34.com\/blog\/scalability\/varnish-and-node-js\/","title":{"rendered":"Varnish and Node.js"},"content":{"rendered":"<p>While working with a client installation they wanted to run Varnish in front of their node.js powered site to eliminate having node serve the static assets. Socket.io uses HTTP\/1.0 and cannot be cached. Minimally these few lines can be added to their respective functions and things will work. Obviously you&#8217;ll want to set expires on your static assets, strip cookies where possible, etc.<\/p>\n<pre>\r\nsub vcl_recv {\r\n    if (req.url ~ \"socket.io\/\") {\r\n      return (pipe);\r\n    }\r\n}\r\n\r\nsub vcl_pipe {\r\n    if (req.http.upgrade) {\r\n        set bereq.http.upgrade = req.http.upgrade;\r\n    }\r\n    return (pipe);\r\n}\r\n<\/pre>\n<p>Tested with: Varnish 3.0.4, Node.js v0.10.13<\/p>\n<div style=\"float:left;\">\n<div id=\"fb-root\"><\/div>\n<fb:like href=\"https:\/\/cd34.com\/blog\/scalability\/varnish-and-node-js\/\" width=\"250\" send=\"false\" show_faces=\"false\" layout=\"button_count\" action=\"recommend\"><\/fb:like>\n<\/div><div style=\"clear:both;\"><\/div>","protected":false},"excerpt":{"rendered":"<p>While working with a client installation they wanted to run Varnish in front of their node.js powered site to eliminate having node serve the static assets. Socket.io uses HTTP\/1.0 and cannot be cached. Minimally these few lines can be added to their respective functions and things will work. Obviously you&#8217;ll want to set expires on [&hellip;]<\/p>\n<div style=\"float:left;\">\n<div id=\"fb-root\"><\/div>\n<fb:like href=\"https:\/\/cd34.com\/blog\/scalability\/varnish-and-node-js\/\" width=\"250\" send=\"false\" show_faces=\"false\" layout=\"button_count\" action=\"recommend\"><\/fb:like>\n<\/div><div style=\"clear:both;\"><\/div>","protected":false},"author":15,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[12],"tags":[293,21],"class_list":["post-1553","post","type-post","status-publish","format-standard","hentry","category-scalability","tag-nodejs","tag-varnish"],"_links":{"self":[{"href":"https:\/\/cd34.com\/blog\/wp-json\/wp\/v2\/posts\/1553","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/cd34.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/cd34.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/cd34.com\/blog\/wp-json\/wp\/v2\/users\/15"}],"replies":[{"embeddable":true,"href":"https:\/\/cd34.com\/blog\/wp-json\/wp\/v2\/comments?post=1553"}],"version-history":[{"count":3,"href":"https:\/\/cd34.com\/blog\/wp-json\/wp\/v2\/posts\/1553\/revisions"}],"predecessor-version":[{"id":1556,"href":"https:\/\/cd34.com\/blog\/wp-json\/wp\/v2\/posts\/1553\/revisions\/1556"}],"wp:attachment":[{"href":"https:\/\/cd34.com\/blog\/wp-json\/wp\/v2\/media?parent=1553"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/cd34.com\/blog\/wp-json\/wp\/v2\/categories?post=1553"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/cd34.com\/blog\/wp-json\/wp\/v2\/tags?post=1553"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}