Apache vs NGINX – A Developer’s Guide to Web Server Selection

1
2165

When it comes to web development you have most likely heard the server debate of: Apache vs NGINX. In this guide I’m going to walk through an overview of each option and list the pros and cons. By the end of the material I hope that you will have the information you need to make an advised decision on which web server to use.

Web Server Overview

Apache vs NGINX

Before we dive into the Apache vs NGINX debate, let’s examine a quick review of what tasks a web server performs. A web server sits on top of a machine and receives HTTP requests. These requests can be things like:

  • Running a Google search
  • Going to a website
  • Essentially anytime you access or interact with a website or application

From there the web server is tasked with the job of communicating with the application on the server. When you run a Google search for cute kittens Google’s web server passes that request to the Google application and the application returns a list of adorable kitties.

Apache vs NGINX

With this data in hand the web server sends back an HTTP response with your cute kittens to your web browser.

So a web server essentially acts like the messenger between a user and the application they want to interact with.

Apache vs NGINX

Now that you know, at a high level, what a what server does, let’s decide on which one is right for you. The two most popular web server options are Apache and NGINX.

Both of these options are open source and free to use. Additionally, they’ve both been on the market for years and have excellent documentation and support.

Pros to Apache

Let’s start by discussing the pros to using the Apache web server.

  • First, Apache allows developers to utilize .htaccess configuration files in directories. These files allow system admins to designate the way that Apache will process requests at a directory specific structure. This is a powerful tool, especially if you have your own server that you want to run multiple shared applications on.
  • Next, Apache is very friendly towards PHP development. In fact the A in the popular LAMP stack server configuration actually stands for Apache. If you are running a PHP application, Apache is most likely going to be the best option for your app.
  • Lastly the Apache web server is feature rich. The development team behind Apache has spent a tremendous amount of time building in functionalities into the web server to make life easier for developers. If you have never configured a web server before, Apache may be the best choice for you.

Cons to Apache

Now let’s go through a list of the cons of using Apache:

  • First on the list is that Apache is considered a heavy web server. Apache typically can’t handle concurrent requests as well as NGINX due to the way it was built.
  • Also, when it comes to serving static content Apache is 2.5 times slower than NGINX. So if your application has a large amount of static content and performance is a priority, Apache may not be the best fit for your needs.

Pros to NGINX

So now let’s walk through the pros for the NGINX web server.

  • My favorite part of NGINX is how it is structured. It was crafted to be a lightweight server that doesn’t try to do too much. This means that NGNIX is rarely the bottleneck when it comes to application performance.
  • NGINX also handles concurrent connections very well. In fact the entire system was created in 2002 to win the C10K Competition. This competition was formed around the challenge of building a web server that could handle at least 10,000 concurrent connections.
  • Lastly, NGINX manages a number of advanced features such as reverse proxy configuration and load balancing quite efficiently.

Cons to NGINX

To finish this guide up let’s walk through a few negative aspects of using NGINX.

  • Due to its lightweight nature NGINX is not as feature rich as Apache. Where Apache attempts to make life easier for developers by managing the system configuration, NGINX requires dev op teams to add layers to manage a number of outside processes. I personally don’t view this solely as a negative since it simply means that I need to map out some additional services, however it’s good to know.
  • Also, if you’re using a Windows server NGINX is relatively limited. Apache offers full support for Windows systems whereas NGINX focuses on Unix like platforms.

Summary

In summary, in the Apache vs NGINX debate really comes down to what type of application and system you are deploying. Both servers have their respective strengths and weaknesses, however they are both great tools for developers. Lastly, it’s important to note that it’s possible to use both systems at the same time. A popular convention is to layer NGINX on top of Apache to utilize both servers. This type of structure allows developers to take advantage of load balancing and rapid processing from NGINX while utilizing Apache’s comprehensive support.

1 COMMENT

LEAVE A REPLY

Please enter your comment!
Please enter your name here