Is Varnish with nginx better than just using nginx? [closed]

I see a lot of talk about using nginx with Varnish and I do not understand why. Isn't nginx enough?

Nginx has SSI, has reverse proxy cache, is lightweight, has SSL, can work with cgi, fpm, etc.

Varnish has the same things, but no ssl, and no cgi support.


I've found varnish ~5% faster for small static files than nginx -- varnish in front of apache, or varnish in front of a web app server would be big gains; but in front of nginx, the benefit is pretty negligible (especially with overheads and extra complexity taken into account)


First, to clarify: Nginx is a web server, with all of the features and complexity that entails. It also has caching capability, but that is not its primary design goal.

Varnish is not a web server. It cannot fill that role (not without a truly evil VCL, anyway). Its role is to cache content provided by another server. If needed, it can alter the request or the response.

If nginx can handle your traffic, then it is enough. If nginx is not able to keep up, then one way to increase its capacity is by placing a cache in front of it and having the cache handle as many of the requests as possible.

As an example, we use Apache to run a number of relatively complex PHP websites from a cluster of web servers. When we started to experience capacity problems, we placed a pair of Varnish servers in front of the Apache cluster. The Varnish hosts now handle 85% of all incoming requests without bothering the Apache backend.