Comparison between Apache and Nginx

Both Apache and Nginx are popular and are used in wide variety of applications .
Most of the time it become an important decision to choose between Nginx and Apache for their application .Apache is more popular than Nginx because it covers more use cases and it has been around much longer, hence more people know about it .

Say for example :
With Apache, you just need to run/maintain/configure a single software that handles everything you might need like static files (css/js/images), PHP , Python, etc. It supports a lot of configuration options that cater to various use cases but is a little resource heavy (i.e. uses more CPU/RAM).

Nginx, on the other hand, just serves static files and also allows you to load balance (transfer your incoming request to one among a set of servers, depending on load), and some other stuff too. But it is much lighter on resources. Moreover, you would have to use something else to handle your dynamic content (PHP (programming language)/Python). Thus, you would have to run/maintain/configure multiple pieces of software.

Apache makes copies (process forks) of itself for every request, be it PHP or a css file. Each running version eats up more RAM. So you have a very low limit on the number of things it can do at one time.

Nginx on the other hand uses a fixed amount of RAM because it is event driven. So you can use your RAM for other things, like PHP

So from my side a piece of advice ,Use Apache if you just want to manage one thing and don’t mind resource usage and use nginx if you have lots of static content or are resource constrained or you like to use “the right tool for the right job”!

Why nginx is good at serving static files?

It’s not any better/worse at serving static files than Apache. However, the big difference is that nginx can serve a lot more users without using up additional resources.

Apache makes copies (process forks) of itself for every request, be it PHP or a css file. Each running version eats up more RAM. So you have a very low limit on the number of things it can do at one time.

Nginx on the other hand uses a fixed amount of RAM because it is event driven. So you can use your RAM for other things, like PHP.

Why nginx + apache?

nginx is configured to serve the static (js, css, img) files. So you have a fixed amount of ram handling all the regular files. No need to use up a fat copy of apache to serve something simple.

apache+mod_php, can just focus on creating dynamic HTML. Which means more effective use of your precious RAM.

For more details please go through these links :

Apache vs nginx – WikiVS
Nginx Vs Apache in AWS – Updated
Web Server Performance Comparison
Nginx overtakes Apache as the server of choice for the top 1000 trafficked sites
Apache vs nginx {performance comparison}
Apache2 vs Nginx for PHP application

I use both on a few projects. Apache for the main web server and nginx as a caching server only sitting in front of Apache.I use Nginx for static content and caching.
Apache remains better for production as it provides an important range of handful plugins.

Advertisements