Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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.

share|improve this question

closed as not constructive by Wesley, Scott Pack, EEAA, Tom O'Connor, voretaq7 Dec 21 '11 at 17:27

As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance.If this question can be reworded to fit the rules in the help center, please edit the question.

    
"Better" is really subjective. It depends on your use cases... –  voretaq7 Dec 21 '11 at 17:30
6  
Sometimes a simple question do the job better than complex ones. I am very concerned about actions like that from the people who closed this question assuming it was no good to the "original Q&A format". I am searching about this subject and I was very interested to see the outcome of this debate. –  Roger Apr 29 '12 at 7:29
    
varnish has powerful vcl configuration, purge, reverse proxy cache, ESI nginx can work with FCGI, reverse proxy cache, ssi, no purge(maybe there is a module) performance wise they are almost the same for static files, caching...if you have any question i can help –  Bogdan Cosmin Aug 27 '12 at 11:04
add comment

2 Answers

up vote 14 down vote accepted

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)

share|improve this answer
add comment

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.

share|improve this answer
    
So, Varnish caches the dynamic content generated by PHP? Or just the other stuff? –  Alix Axel Dec 1 '12 at 22:14
    
Varnish caches whatever you tell it to cache. It can cache just the PHP output, just the static files, both, or neither. It's a very powerful tool. –  Insyte Dec 6 '12 at 22:52
    
I was asking about your specific example. It baffles me how it's possible to cache dynamic content without messing up the dynamic application (PHP sessions for starters). Caching static content seems a bit redundant to me. –  Alix Axel Dec 7 '12 at 1:10
2  
It depends on the dynamic content. Say, for example, that the page is a blog post with comments. It may be extremely expensive to generate the comment thread but perfectly acceptable to cache it for 5 minutes. On the other hand, caching the dynamic content returned by a webmail application would clearly be problematic. You can even create a mixed case: Cache the full output of an ecommerce app, but tell varnish to call back to the backend to populate the shopping cart indicator. –  Insyte Jan 2 '13 at 23:34
add comment

Not the answer you're looking for? Browse other questions tagged or ask your own question.