Node.js, Nginx and Varnish with WebSockets
Posted
by
Joe S
on Server Fault
See other posts from Server Fault
or by Joe S
Published on 2012-09-21T10:30:14Z
Indexed on
2012/09/22
3:39 UTC
Read the original article
Hit count: 552
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?
© Server Fault or respective owner