Posts Tagged ‘nodejs’

Varnish and Node.js

Thursday, July 18th, 2013

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’ll want to set expires on your static assets, strip cookies where possible, etc.

sub vcl_recv {
    if (req.url ~ "socket.io/") {
      return (pipe);
    }
}

sub vcl_pipe {
    if (req.http.upgrade) {
        set bereq.http.upgrade = req.http.upgrade;
    }
    return (pipe);
}

Tested with: Varnish 3.0.4, Node.js v0.10.13

Entries (RSS) and Comments (RSS).
Cluster host: li