Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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?

share|improve this question
Haven't you tried ? – DukeLion Sep 21 '12 at 10:48
I've not tried it yet, the general feeling that I got was that the varnish solution was preferable. I guess the reason I haven't tried that yet is that it seems quite experimental, this could simplify things though (albeit requiring a custom Nginx build). Will experiment. – Joe S Sep 21 '12 at 11:10
varnish can load balance – Mike Sep 21 '12 at 13:36

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 (

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

share|improve this answer

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.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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