5 ms·
WebSockets with Varnish and Nginx
- PleaseBeSerious 14y agoIf you have Varnish then why have nginx? Is there an advantage to having nginx do the request routing?
- roschdal 14y agonginx can compress your HTTP traffic, while Varnish can't. So there are some things you would need nginx for. However, I really think that nginx should implement proper support for WebSockets by now. I have requested this previously, but the request got unanswered.
- sureshv 14y agoFYI, compression was added to Varnish in 3.x: https://www.varnish-cache.org/docs/3.0/tutorial/compression.html https://www.varnish-cache.org/docs/3.0/tutorial/compression....
- jiggy2011 14y agoI would think nginx would be better for holding open long "keep alive" connections than Apache or IIS if you are doing long polling etc. Of course if you are just forwarding to another backend you may lose this.
- Argorak 14y agoWell, the sample is incomplete. Often, you also need a server for serving static files, which Nginx is really good at, but Varnish cannot do.
- ibotty 14y agothis does not address the problem with ssl-traffic. varnish will delegate it to a reverse proxy _in front_ of itself. i usually deploy nginx. looks like a catch-22 for websockets ;).
- conesus 14y agoSo how do you handle the case of SSL in front of web traffic and web socket traffic? I need to handle both SSL and non-SSL. Right now I just use another port, but my users behind a firewall can't access the websocket.
- iamleppert 14y agoI like this technique! Only caveat is it adds another piece of infrastructure (Varnish) to your stack which while Varnish is very good, some people may not want to. But nice writeup!
- otterley 14y agoVarnish allocates one thread per connection. Even if it supports websockets, it's not going to scale well across tens of thousands of simultaneous persistent connections. The context switch and memory overhead will be considerable. For now, Java-based servers (using netty) and node.js may be a better idea.
- pestaa 14y agoNot only that, but letting all traffic through Varnish is not a good utilization of its resources at all. The question is, how could I set up multiple servers on the same port? Or what else do I need to put in front of Varnish to route WebSocket connections elsewhere? I'm starting to think this use case is not easy to solve under one IP address.
- 2mur 14y agoNode Http Proxy: https://github.com/nodejitsu/node-http-proxy https://github.com/nodejitsu/node-http-proxy No need for Varnish for proxying your websockets.
- thruflo 14y agoThanks for the link. This looks like an ideal tool to fulfil the same role as Varnish (in the stack I'd outlined) without losing SSL support or allocating one thread per active connection.
- sureshv 14y agoVarnish sits in front on port 80 then proxies based on the VCL configuration, you can parse the HTTP headers/path to pass through appropriately. https://www.varnish-cache.org/docs/trunk/tutorial/websockets.html https://www.varnish-cache.org/docs/trunk/tutorial/websockets...
- newman314 14y agoOne of the things I've debated back and forth personally is if it's better to put nginx in front of varnish or vice versa. There are reasons to do either but I've not come up with a definitive reason to go one way or another.
- deleted 14y ago[deleted]