Curious about NGINX? Wondering why you should switch from Apache to NGINX - or why you shouldn't? Most Linux servers come with Apache pre-installed. Why go to the trouble of installing an entirely different web server, when Apache is right there?
Apache is the most popular web server in the world, by a wide margin, and it has been for two decades, since 1996. "Popular" doesn't necessarily mean "good," but Apache's widespread usage is certainly a vote of confidence from the sys admin community at large.
Apache's prevalence also means that there are lots of resources available if you need help. There are thousands of Apache communities, forums, tutorials, websites, and books which can help you learn more about Apache, solve problems, and get the most out of your Apache installation.
However, many websites large and small are finding it worth their while to expend the time and effort to switch to NGINX.
If you are an experienced website admin, you have no doubt already spent hours learning how to use Apache, and grappling with its various quirks and foibles. It can be intimidating to consider switching to a new web server.
However, NGINX (which is pronounced "Engine X") has been designed from the ground up to be easy-to-use and understand. Most people find that it is far easier to learn how to use NGINX than it was to learn Apache.
If you are new to website administration, you may want to take this into consideration. It's always good to learn how to use what everyone else uses (Apache) so that your skills are portable. However, Apache can be a difficult and frustrating web server to work with. If you are just starting out, NGINX may be a better choice.
Who Uses NGINX, And Why?
Although NGINX works very well for small and mid-sized websites, it really shines when used to deliver high-traffic sites. NGINX has been designed and tuned for high performance under difficult conditions.
Not coincidentally, these are the conditions under which Apache performs poorly. Although Apache is reliable, it is notorious for struggling under heavy loads. If a website sees a sudden spike in traffic, Apache's performance will suffer, page load times will increase dramatically, and if the demands are high enough, the entire web server can grind to a halt.
Although Apache can be tuned to improve its performance, it can never match NGINX's performance "out of the box." If your website has been experiencing performance constraints, NGINX is an excellent candidate.
How NGINX Improves Performance
Apache's main problem is the way it handles concurrent requests. Apache can serve a large number of requests per second, but as the number of requests increases, Apache's performance begins to slow.
NGINX is event-based, which means that it does not need to spawn a new thread or process for each request. This means that the number of concurrent requests has almost no effect on NGINX's performance, and it keeps NGINX's memory usage low.
Where Apache spawns new processes and threads to handle incoming connections, NGINX spawns only a few processes - each of which can handle thousands of concurrent connections.
One area in which Apache arguably out-performs NGINX is dynamic content. Apache has the built-in ability to parse and execute many forms of dynamic content, including PHP, Python, and Perl. This is not only convenient for the developer, it's also efficient.
By comparison, NGINX has to hand dynamic content requests off to a processor to be executed, wait for the content to be rendered and passed back, and then deliver that rendered content to the browser. These added steps can make things more complicated, particularly during the initial set-up stage.
To its credit, NGINX handles this situation as efficiently as possible. It delivers static content as usual, and only contacts the external processor when needed.
Because NGINX works so well as a reverse proxy, and Apache does such a good job of handling dynamic content, many servers use both. It is becoming increasingly common to find Apache being used as the back end, with NGINX as the proxy server on the front end handling requests.