I'm in the process of architecting the backend of a new Node.js web app that i'd like to be pretty scalable, but not overkill. In all of my previous Node.js deployments, I have used Nginx to serve static assets such as JS/CSS and reverse proxy to Node (As i've heard Nginx does a much better job of this / express is not really production ready).

However, Nginx does not support WebSockets. I am making extensive use of Socket.IO for the first time and discovered many articles detailing this limitation. Most of them suggest using Varnish to direct the WebSockets traffic directly to node, bypassing Nginx. This is my current setup:

Varnish : Port 80 - Routing HTTP requests to Nginx and WebSockets directly to node
Nginx : Port 8080 - Serving Static Assets like CSS/JS
Node.js Express: Port 3000 - Serving the App, over HTTP + WebSockets

However, there is now the added complexity that Varnish doesn't support HTTPS, which requires Stunnel or some other solution, it's also not load balanced yet (Perhaps i will use HAProxy or something). The complexity is stacking up! I would like to keep things simpler than this if possible.

Is it still necessary to reverse proxy Node.js using Nginx when Varnish is also present? As even if express is slow at serving static files, they should theoretically be cached by Varnish. Or are there better ways to implement this?


Is it still necessary to reverse proxy Node.js using Nginx when Varnish is also present?

Varnish can cache your static files from node.js app. You need to provide correct http headers (cache-control) from your app (for default VCL). Or you can tune your VCL to cache static files based on URL or for example contenet-type.

For SSL/TLS suport I'm using Pound with Varnish (http://www.apsis.ch/pound).

As it was noted in comments Varnish can also be load balancer.


No matter what pieces of software you'll be using, you still need these features implemented:

  1. websocket backend
  2. application backend
  3. static backend
  4. reverse proxy
  5. content cache
  6. http router
  7. loadbalancer
  8. https filter

Complexity is not about how many pieces of software you are using - it's more depending on how many configuration features you have. It's more simple to have bigger number of dedicated software than different modules with duplicated features in play.

For other question: it's usually bad to chain-up reverse proxies, so you'd better set up varnish to use nginx only as static backend, or use node.js for this and set up caching in varnish to achieve required performance.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.