0

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?

John Gardeniers
  • 27,458
  • 12
  • 55
  • 109
Boop
  • 11
  • 2
  • Haven't you tried https://github.com/yaoweibin/nginx_tcp_proxy_module ? – 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. – Boop Sep 21 '12 at 11:10
  • varnish can load balance https://www.varnish-cache.org/trac/wiki/LoadBalancing – Mike Sep 21 '12 at 13:36

2 Answers2

0

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.

RJS
  • 1,479
  • 9
  • 9
0

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.

DukeLion
  • 3,259
  • 1
  • 18
  • 19