Support

Find answers, guides, and tutorials to supercharge your content delivery.

Comparing Varnish® vs Nginx

Updated on October 4, 2018
Comparing Varnish® vs Nginx

Both Varnish® and Nginx is software you can take advantage of as a web developer or site maintainer to help improve the speed of your website and or app. We've written about using a Varnish® CDN stack as well as multiple Nginx topics in the past, however, in this post we're going to discuss what differences exist between Varnish® vs Nginx.

Although both solutions aren't fully comparable, we can analyze certain aspects of both technologies and then compare them against each other; which is what we aim to achieve in this post.

Varnish® vs Nginx

Before jumping right into comparing certain aspects of Varnish® and Nginx. We'll first provide a little overview of each technology.

  • Nginx is an open source web server that can also be used as a proxy. Some of the largest trafficked websites use it as their web server of choice as it is known to be efficient and fast in the way in handles concurrent connections. Furthermore, certain Apache web server users take advantage of Nginx in combination with Apache by using it as a reverse proxy. Learn more in our Nginx vs Apache post.
  • Varnish® on the other hand, is not a web server at all. Rather, its purpose is to act as a frontend accelerator or reverse proxy. However, unlike Nginx, it is not a standalone solution to run an entire application. You still require a dedicated web server in order to use Varnish®. VCL, or Varnish® Configuration Language, is the language used in Varnish® in order to specify certain request handling rules and caching policies.

Now that we've covered the basics of each solution, we can see that they are not directly comparable in every sense. However, in respects of using one or the other as a reverse proxy, there are a few comparisons to be made.

Features

In terms of comparable features, Nginx and Varnish® are quite similar. For instance, both solutions can be used as a reverse proxy and load balancer. They also allow you to configure cache and can help protect against DDoS attacks. However, there are also a couple differences such that Varnish® supports ESI where Nginx does not, however, Nginx supports SSL where Varnish® does not. Additionally, it was not until recently (September 2016) that Varnish® just started supporting HTTP/2.

Speed

When it comes to speed, there are tests results that favor either end of the spectrum. Some tests conclude that Varnish® is the faster option while others conclude that Nginx is faster. Certain variables can affect the results of a test such as concurrent user load, cache configurations, etc. That being said, the folks over at deliciousbrains performed a couple of tests using Nginx's Fast CGI and Varnish®. The following test was performed using Nginx.

This test shows that after 27,170 hits, the average response time was 82 ms. Now a similar test was performed for the Varnish® setup.

Similarly, this test generated 26,440 hits however the average response time for this setup was 100 ms.

Caching capabilities

When it comes to actually caching static content using Varnish® vs Nginx there is a difference that exists in terms of flexibility and purging. Varnish® is known to have greater flexibility and allows you to create a more complex caching structure as compared to Nginx. Varnish® also comes with a built-in mechanism that allows you to purge content. Nginx on the other hand, does not natively support this. However, it does offer the fastcgi_cache_purge module to satisfy this need.

Although Varnish® is more flexible, the Nginx Fast CGI should certainly be versatile enough to meet most caching requirements.

The case for Nginx

  • Many speed tests show that Nginx Fast CGI is faster
  • Consumes less memory
  • Supports SSL and was much faster in adopting SPDY and HTTP/2 support
  • Apart from just being used as a reverse proxy, it can also be used as a complete web server solution
  • Smaller learning curve

The case for Varnish®

  • Ability to create a more flexible / complex cache structure
  • Built-in purging capabilities
  • Support ESI

Summary

In conclusion, there are two sides to every coin. In certain cases, Nginx may be a more suitable option and in others, Varnish® may be the answer. However, overall when it comes to answering the question of which solution is better - Varnish® vs Nginx - in the majority of cases the answer will likely be Nginx.

Even though Varnish® is known to be more configurable in terms of cache settings than Nginx, Fast CGI is still quite configurable in it of itself and will satisfy the majority of user requirements. If you're still not convinced on which solution is better, try them both out on your own and run a couple of comparison tests. Every use-case is different and you might very well find that Varnish® is the better option for your project.

Supercharge your content delivery 🚀

Try KeyCDN with a free 14 day trial, no credit card required.

Get started
KeyCDN uses cookies to make its website easier to use. Learn more