NGINX vs Apache: A Homelabbers Opinion

NGINX vs Apache, often debated and rightly so. Both these popular web servers have their many strong point as well as weaknesses. It's up to you to decide what you think is the best for your application. When trying to decide, you have to remember there is no ideal solution, only the best for you. This post will go over my opinions on the subject from a Home lab/Self hosted viewpoint.

Now with all that aside, in my opinion, NGINX is the best for home servers. Here are a few of the key reasons:

  • Performance: NGINX was originally created to address some problems with Apache, including it's size and performance. It is likely better for your home server because it has a lower overhead resource usage.
  • Reverse Proxy: When selfhosting, you often find yourself with a number of services running on different ports and virtual machines. NGINXs reverse proxy lets you access them at a convenient URL.
  • Ease of Configuration: NGINXs configuration files or "server blocks" as their called, are extremely easy to understand and are all located in one place.
  • Speed: Tests have proven NGINX to be over 4 times faster than Apache, under the same circumstances!

Performance

First and foremost in the NGINX vs Apache debate is performance. To understand why NGINX comes out on top, we first need to understand how the two work. Apache is a one-thread-per-process style program, whereas NGINX is an event-driven, asynchronous model. The main difference here is when traffic increases, Apache starts to struggle while NGINX handles it all no problem. NGINX also has a considerably smaller code base decreasing the number of attack vectors and generally improving performance.

Reverse Proxy

NGINXs reverse proxy is one of its biggest pros, especially for self hosting. It allows you to access services run on other ports, machines or virtual machines through your NGINX server. instead of accessing a service at my.ip:8989, it can be just my.domain/myservice. You can also encrypt the traffic with SSL. See the diagram below for more info on how it all works:

Configuration

Apache is configured at the directory level with the use of .htacess files in the given directory. This is convenient for shared host where you don't have access to the base virtual server config file - not a common issue when you run your server. The downside to the .htaccess files is they are more server requests to deal with. NGINX has everything in the base server block file - no need to hunt around for a bunch of files in a bunch of directories.

Speed

The graph below really says it all when it comes to speed and performance. With 1 request, both are very similar but as the requests increase, NGINX clearly comes out ahead:


Hopefully this short guide has helped you choose NGINX vs Apache for your home lab. If you want a guide for all the basic NGINX config, look no further.