General

Nginx vs Apache: Which Web Server Is the Best?

There was a time when apache had such a great big chunk of business in web servers because it was running on more than half of the web servers, and this question was rendered moot just by looking at the market. But now things have changed, there are streams of new web servers and the all mighty apache has been falling in numbers and is now down to nearly a third of what it used to be. Now there is a web service rising slowly and making its name in the big leagues, the “NGINX” (you pronounce it “engine-x”) and it is making steady progress and gaining about 1% (give or take) of total web servers each year. There is a reason for this steady progress and why it’s such a great web service as of right now and why people are changing over to “nginx”.

When you search about web servers you will notice that apache and nginx are at the top and these are two most common names you will hear these days in  the conversations of web servers so it is the best time to discuss which one is the best? Is it the apache the old reliable web service that used to be the king of the hill until now or nginx the new competitor who promises a lot? To compare both we can go through certain areas like: –

  • OS support
  • Security of the web servers
  • Flexibility with writing modules
  • Documentation (apache modules and NGINX wiki)
  • Performance for Dynamic content VS Static content
  • File Sharing (Apache .htaccess)

If we are only comparing the site traffic alone which can be a great comparison for the market we can see that the apache holds the record with 46% but the new nginx is at 24% and gaining about 3% (on average) every year which makes it really competitive and relevant to compare both services. When talking about file sharing due to the famous Apache .htaccess file (even more improved in Apache 2.4.7 Exploit) gives it a huge upper hand in shared hosting which is sometimes a dealbreaker for people while looking at nginx. But the new nginx has better features, more enhanced GUI, and better dynamic content. This is just a small comparison; there are lots of things we can go over while comparing these two.

When talking about brute performance numbers nginx performs better (almost 2.5x times better) than apache. Simulation testing has shown results that nginx is way faster than apache and uses less memory while doing the same work (about 4% less). But this is the case only in static content, when comparing the dynamic content and running simulations for it we see that both apache and nginx have similar results.in terms of PHP and other languages the dynamic web page performance is same between both the nginx and the apache model (PHP-FPM + FastCGI). Apache when linked with PHP-FPM handles almost the same traffic and speed as Nginx with PHP. Apparently having high static content transfer speed does not mean the dynamic content would be just as fast too since there are other factors to be looked at which makes them come out even in this area.

Since apache has been around for a while the OS support is better compared to that of nginx. Apache (with the new Apache 2.4.7 Exploit) fully supports Microsoft windows and Unix-based platforms. Nginx also has support in windows and UNIX platforms, but it is not that detailed, and apache has a clear edge in this. The security is efficient and excellently managed in both the web servers, apache offers HTTP DoS, DDoS, or brute force attacks while nginx code is considerably small but has almost the same strength as apache.

Both apache and nginx can be easily customized to your liking by writing the modules but the flexibility issues for the dynamic module loading has no kind of support before 2016 in nginx which makes it tougher for people trying to add dynamic functionality to their site. But apache being an old member fully supports dynamic content loading and has all kinds of documentation and a guide which gives it an upper edge.

There is no equivalent of Apache .htaccess in nginx. .htaccess allows users to have a lot of functionality in their hands and they can change things however they want to. It allows them to bypass system settings for any given directory and it also provides a big documentation where you can basically find everything you need while working with apache. With nginx wiki we see that it also provides similar support (documentation with guidelines and tips) to that of Apache .htaccess which makes them even in this area. Nginx also provides online training sessions and provides exam certificates after you clear out proper training which help you understand nginx much better.

Nginx which is better for static content and offers extra performance when using dynamic content makes a great compelling case. Its advanced and useful features like media streaming (at a really high speed), reverse proxy for HTTP and non-HTTP protocols and along with its great documentation are things we all wish for in a web service. While the people who want to use the shared hosting 90% of the time go with apache (there are other web services with shared hosting too) since it is the obvious choice for them because of the Apache .htaccess. apache also handles the dynamic modules very efficiently which also makes a great plus point for people going with apache.

Comparing the common features, we can see that the battle between the web services is a real close fight. But in the end it all comes down to your needs and what you prefer in a web service. What features you need and what you can live without will only let you decide which web server you should go with. Also, you should remember that regardless of what server you pick you still need a Linux hosting provider which is essential for hosting (shared or virtual servers).