I have an application running behind a proxy, both on the same machine. Which approach is more suited regarding compression, while preserving reasonable performance.
- turn on compression at the application level (which happens to be in nodejs)
- leave it out to the proxy (which is nginx)
20
While this is probably a better question for ServerFault, I believe there is a clear answer: do compression on nginx.
There are a couple of reasons for this:
- Compression is moderately CPU-intensive, and Node is single-threaded. Therefore, compression in node will potentially reduce the total number of requests a single server is able to handle.
- You will almost certainly use nginx to serve static assets such as JavaScript, CSS, images, and static HTML. Which you will want to compress. So why not compress everything that goes through nginx, including forwarded traffic?
As for both: that’s just wasted CPU.
5
Presuming your nginx server fronting node is proximate to said node server you get just about nothing out of using things like compression between the two. You’ve got plenty of bandwidth between the two, why waste CPU saving it? Moreover, if you are doing any rewrites in nginx it gets ugly as nginx has to unzip the contents, replace, and re-zip. If it lets ya do it at all.