World Wide Web (WWW), invented in 1989, made the internet ubiquitous by creating a channel for information which is now available like never before and can be located by a unique address (URL). Users can now access almost any information through its URL- by making HTTP requests to hosting web servers which are powerful interconnected computers responding to those requests. Apache and Nginx are the most popular web servers that power the Internet today. Both of them have unique capabilities catering to particular computing requirements, therefore making one more suitable than the other in various scenarios.
What is Apache?
Apache is an open source web server software developed in 1995. It is easy-to-use, powerful and compatible with all major OS platforms. It has a large set of features that can be enabled by installing separate modules. It has a simple architecture wherein the request processing is done by various multi-processing modules (MPM). Many network services are started from a master service inetd. It creates a new httpd process for every new connection request (A process per connection).
Apache was developed in the early days of the internet when the traffic was relatively lower on websites and the web pages were static in simple HTML. Today, there has been an explosive growth in the volume of traffic and the number of users seeking dynamic content on the web. There can be millions and perhaps multiple simultaneous connections to a large scale enterprise web server. Commonly, web browsers open multiple TCP connections to a web server to decrease page?rendering time for each user session so that resources can be downloaded instantly in parallel. Browsers keep these connections open (Keep-alive) for a certain period of time to reduce delay for future requests a user might make during the session. Each open connection exclusively reserves an httpd process. A large number of httpd process thus created can cause considerable load on the server resulting in its performance degradation and frequent crashes. With its process per connection model, Apache is not efficient to handle many concurrent connections.
Apache creates a large number of processes which competes for a common RAM, CPU and other resources.
However, to handle a large number of requests and check resources for over- consumption, Apache developed the following strategies which can be implemented through MPM packages. But the performance is still degraded while handling concurrency.
Worker model: This creates a single control process that is responsible for launching child processes. Each child process then creates a fixed number of threads, as well as a listener thread. The listener thread listens for connections and passes them to a thread for processing when they arrive. Though this model scales much better than the pre-fork method- which we discussed as a process per connection model, it can still run into scaling issues for very high-traffic sites, due to the single control process bottleneck.
Event model: This is similar to the worker model, but it creates one listener thread which listens for connections and passes them to a worker thread for processing. This MPM handles long-running connections much more efficiently on a single thread (Keep-alive handling). Since Apache 2.4, the event model has been deemed stable and is now also the default setting if the operating system can support it.
What is Nginx?
Nginx is also an open source web server software which was developed in 2002 to improve the performance of Apache-based services and for high concurrency. It is highly scalable and can handle many concurrent connections. NGINX uses an asynchronous, event-driven architecture to handle these massive amounts of connections. This architecture makes handling high and fluctuating loads much more predictable in terms of RAM usage, CPU usage, and latency. NGINX does not set up extra worker processes per connection. In most cases, the recommended NGINX configuration is running one worker process per CPU, maximizing the hardware’s efficiency. Each worker process can handle thousands of HTTP connections simultaneously. This results in a highly regarded implementation that is lightweight, scalable, and high performance.
Which are the other differences between the two?
Not fast as NGINX
|NGINX is 2.5 times faster than the Apache web server in running concurrent connections. NGINX serves static content much faster than Apache.
|Configuration||Easy to configure||Easy to configure.|
|OS support||Runs on Linux, Windows.||Runs on Linux. It runs on Windows also but not efficiently.|
|Customisation (Dynamic Loading)||Easy. You can simply add or remove modules||Highly customisable. Some modules require being compiled into binary.|
Good documentation available
|Initially, limited documentation was available in only Russian language. Now NGINX has a good documentation.|
A large community support is available free of cost. Third party organisations also provide premium support.
A large community support is available free of cost. Official support NGINX plus is provided at a premium.
Which of them is the best? What is the best configuration?
As explained, Apache or NGINX both are the best choices according to a situation. However, the best configuration is combining both of them to deploy in a single environment- NGINX as a proxy server in front of an Apache web server. NGINX performs the HTTP?related heavy lifting like serving static files, caching content, and offloading slow HTTP connections while the Apache web server can run the application code in a safe and secure environment without concerning about extra loads. NGINX can serve as a proxy that forwards HTTP requests to upstream web servers (such as an Apache backend) and FastCGI, Memcached, SCGI, and uWSGI servers. NGINX does not seek to implement the huge range of functionality necessary to run an application but relies on specialized third-party servers such as PHP?FPM, Node.js, and even Apache. This configuration is widely used in an enterprise setup.
Apache is like Microsoft Word—It has many features but you only need few. NGINX has those few features, and are 50 times faster than Apache.
- Apache versus NGINX – Which Open Source Web Server Software you should choose - April 30, 2018
- Understanding OpenStack - April 30, 2018
- Here is everything you need to know about BlockChain - April 17, 2018