NGINX as a Web Server

NGINX as a Web Server

C10k Problem

NGINX was created to solve the well-known C10k problem.

C10k is a term devised in 1999 to depict the trouble that existing in web servers at that time experienced in taking care of substantial numbers of concurrent connections. The C10k problem refers to the inability of a server to scale large number (the 10K) of clients/connections (the C) due to resource exhaustion and addressing the issue by optimizing network sockets.

NGINX Overview

NGINX was created in 2004 by a Russian Software Engineer Igor Sysoev, as he was frustrated with Apache and wanted to build a replacement of handing 10000 concurrent connections. NGINX solved the C10k problem with its event-driven, asynchronous architecture.

NGINX is an open-source web server which can also act as a reverse proxy server, load balancer, HTTP cache and a mail proxy server.

In this blog post, we will examine and center NGINX as a Web Server. NGINX is a Reverse Proxy Server at its core, and due to this design, it performs so well.

NGINX mainly focus on the below:

    1. High Performance – Fast
    2. Low Resource Usage – Memory Efficient
    3. High Concurrency

NGINX vs. Apache

NGINX is Faster than Apache!! This is the most common perception. But we will see how and why.

NGINX’s core design as a Reverse Proxy Server makes it novel and aids is to outpace Apache in many ways.

As a matter of course, Apache is configured in a prefork mode, which implies it generates a set number of processes, every one of it can process a single request at any given moment. Nevertheless, that request is for dynamic content (PHP Script) or static content (Image).

NGINX on the other hand deals requests asynchronously, which implies a single NGINX process can serve multiple requests concurrently. This number mostly depends on the system resources available to NGINX process. However, this also prevents NGINX to embed server-side programming languages like PHP into its process. This implies all request for dynamic content must be managed with a separate process like PHP-FPM (FastCGI Process Manager) and reverse proxied back to the client via NGINX. This makes NGINX significantly less resource hungry.

A well configured NGINX server, serving both static and dynamic content should always be more efficient and less demanding on system resources compared to a similarly configured Apache server.

Now we know NGINX is Faster than Apache due to the below:

    1. It serves static resources much faster than Apache
    2. It handles a much more significant number of concurrent requests than Apache

Another critical difference is NGINX translates all incoming requests as URI locations whereas Apache prefers to read incoming requests as filesystem locations. This design allows NGINX to function not only as a web server but also as a load balancer or a mail server or an HTTP cache.

Using Both NGINX and Apache

Apache is known for its power and NGINX for its speed. This implies NGINX can serve static contents quicker but it needs help to serve dynamic contents, on the other hand, Apache includes powerful modules required to work with back-end application servers and run scripting languages faster but its memory hungry. Now it’s evident that both NGINX and Apache have their advantages and drawbacks, a better design is to use NGINX in the front as a proxy server for serving static files and forwarding requests and Apache as the backend to serve dynamic content.

Leave a reply:

Your email address will not be published.

Site Footer