Which one is better APACHE or NGINX ?
Awesome Tools Linux Linux Fun

Which one is better APACHE or NGINX ? Part – 1

When have you to choose a web server you always think that which one is better Apache or Nginx? I have tried to make some comparison and hope this will help you to figure out.

But First, let look into APACHE and Nginx

NGINX and APACHE in Market

Apache is a most known web server in the world and late 90s-2011 was the time when the Apache web server was serving around 60 percent of the world websites but now it’s rate of use is decreasing every day and every year. Well, from last few years few web server are emerging with the new idea and replacing the drawbacks of traditional web servers.

According to market research, today Apache and Nginx (pronounced as “engine-x”) are the two most common open source web servers in the world. Today together, the Apache and Nginx are responsible for serving over 50% of traffic on the internet in which Nginx hold 30% of market share and still counting. Clearly, NGINX is enticing the world’s biggest web properties with something.

Web Server Share in market

In this article, we’ll make NGINX/Apache comparisons for the following topics:

  • 1. General Introduction
  • 2. Processing Methodology
  • 3. Performance Test
    • 3.1 Memory Utilization
    • 3.2 Requests Per Second
  • 4. OS Support
  • 5. Security
  • 6. Flexibility
  • 7. Modules Support
  • 8. Content specific Difference(Static/dynamic)
  • 9. Architectural Approach(Distributed/Centralized)
  • 10. File vs URI-Based Interpretation

Let’s start

1. General Introduction:

Apache:

The Apache server was introduced in the year 1995. This server was created by  Robert McCool and now this is being developed under Apache Software Foundation since 1999. This was simply named as “Apache”. This web server is very popular since 1996.  The reason for apache was popularity Apache was due to its flexibility, power, and widespread support.

Nginx:

When apache was in its glory in the mean time In 2002, Igor Sysoev began work on the C10K problem, and as a result, Nginx was developed. The C10K was the challenge for handling 10000 concurrent connection and it was much needed because the internet was growing very fast. The initial launch was made in 2004. The reason for the popularity of Nginx has grown due to its light-weight resource utilization and its ability to scale easily on minimal hardware.


2. Processing Methodology

Apache:

Apache woking can be configured in 3 ways per today date:

Process Model/Pre-Fork Model: when there are many concurrent connections it does not scale itself accordingly and as a result, it consumes a lot of RAM and also may lead to refuse connections at high loads. This methodology is good for the small size websites but big sites with hit traffic will loose it’s woking. This is the original “pre-fork” method. In short, this is “process per request”

Apache Preforf Model

Worker Model: In this, a single process launch which launches child process and every child 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 and solved the bottleneck of pre-fork. In short, this is multi-threaded architecture of apache and there is a Thread per  child process  or ThreadsPerChild

Apache Worker Multi-Thread

Event Model: This Model was inspired from worker model but with a twist of creating one listener thread which listens for connections and passes them to a worker thread for processing. Now This MPM was able to handle long-running connection more efficiently with a single thread (KeepAlive handling). Now with Apache 2.4, the event model is stable and is now also the default setting if OS supports event model.

Nginx:

As the Mentioned NGINX was created as a solution for the modern web which can handle the C10K challenge of handling at least 10,000 simultaneous client connections on a single server. As the design of Nginx was asynchronous and an event-driven, this was able to handle massive amounts of connections. With this new approach NGINX was able to handle high and fluctuating loads much more predictable in terms of RAM usage, CPU usage, and latency.

NGINX Working

3. Performance Test

As a test case with the use of ApacheBench(ab) tool, we made 25000 requests for a 5KB JPG file locally on the virtual Linux server with Nginx, Apache the servers and a different web server.

Where c represent concurrent request and n is the total number of request.

3.1 Memory Utilization

As you can see apache create more thread for more request to handle and use more and as a result, Apache uses more memory while in Nginx you see lees use of memory with the same number of request.

3.2 Requests Per Second

Here you can easily see that Nginx is far better than Apache

4. OS Support

Well, as per OS deployment and set up Nginx is really far behind Apache.

Apache works pretty awesomely on every Linux-Unix based system (e.g., Linux or BSD) and has full support for Microsoft Windows. Though Nginx works on every flavor of Linux -Unix based system and has some support for Windows, but its support for Windows is not as strong as that of Apache.

5.Security

Both the web servers are coded on C so both of these web servers are quite good in the security of point of view. Though Nginx code is smaller then apache so more can be seen under Nginx belt.

Both servers have almost same vulnerability reporting. Apache documentation site has configurations advice for its security for DDoS attack also mod_evasive module which helps in saving web servers from HTTP DoS, DDoS, or brute force attacks. Same Documentation is available for Nginx also and also read how to save Nginx from DDOS.

Still more to go so let’s continue reading Part 2 Here….



Kapendra
Love to write technical stuff with personal experience as I am working as a Sr. Linux Admin. and every day is a learning day and Trust me being tech geek is really cool.
http://kapendra.com

Leave a Reply