NGINX - History, Overview & Uses

NGINX 

History

The C10K problem is the main reason why the next giant of the field, called Nginx, grabbed the stage. One fine morning in 1999, Dan Kegel discovered the issue that all the traditional web servers were incapable of handling 10K concurrent clients/connections and named it the C10K problem.

Web Server

A web server is a computer that processes the HyperText Transfer Protocol (HTTP) requests and sends back the HTTP response to clients. Apache, IIS, and Nginx are the most popular web servers.

HTTP

Wikipedia defines HTTP as the foundation of the data communication for WWW. It is a client-server protocol based on request-response model.

HTTP Request

Client sends a request with the URL of an HTML page.

HTTP Response

The web server transmits back the requested HTML page via an HTTP response.

Protocol and Its Uses

  • When two individuals communicate with each other, they should know a common language to convey their thoughts.
  • The same way when two systems need to communicate, they should follow a common mode of communication; hence they agree upon a common set of rules called a protocol that governs the communication.
  • TCP, UDP, FTP, and HTTP are some of the communication protocols out of which HTTP is considered the most important.

Web Server History

W3C httpd or CERN httpd is the world's first web server developed in 1990s by Tim Berners-Lee and his team at CERN (European Organization for Nuclear Research).

Both Apache HTTP server and IIS were introduced in the year 1995, and even now they are reigning as two giants in the world of web technology.

IBM Websphere was introduced in 1998.

In 1999, Apache released its TOMCAT server to support Java servlets and JSPs.

Let's discuss the C10K Problem.

Threaded servers like Apache cannot handle 10K connections because each connection creates a new thread. The kernel uses O(n^2)* algorithm, so 10K threads are not possible. So, the engineers started moving away from threaded servers to event-driven servers like Nginx*: The Big O notation used for calculating time/space complexity of algorithms.

NGINX

Pronounced EngineX, it's an open source web server or reverse proxy server. It can also be utilized for server load balancing and HTTP cache.

NGINX As Web Server

The Nginx server processes the HTTP requests and sends back the HTTP response to the client. Nginx handles HTTP requests by asynchronous, event-driven method.

NGINX As Reverse Proxy

A reverse proxy is also a proxy server that retrieves data from all the resources on behalf of its client. Nginx supports reverse proxying through the following protocols:

  • FastCGI
  • uwsgi
  • SCGI

NGINX As a Load Balancer

Nginx acts as an effective load balancer for HTTP by distributing requests across multiple applications. It improves the performance, reduces the latency, and also maximizes the throughput. Nginx supports the following algorithms for load balancing:

  • Round Robin
  • Least Connected
  • IP hash

Nginx has three versions,

  • Development
    Highly recommended as it includes fixes for bugs in the stable version.
  • Stable
    Tested and accepted by a community of users and testers.
  • Legacy
    Not recommended as it is an outdated one.

You can furnish your Nginx server by

  • Building it from source 
  • Installing it from binary packages Installation through binary package needs a package manager such as yum.

The easiest way to install Nginx is with Windows.

  • Go to the official Nginx installation page for Windows
  • Download the latest/required Windows release.
  • Extract it anywhere.
  • That is it; you are ready to go!

Nginx is easy to install with windows, but what about the performance?

A Worker (Nginx instance) cannot handle more than 1024 connections concurrently. Only one worker can be used at a time. Windows Vista or later versions do not support cache module. So, Nginx with windows is no longer effective as Nginx with Linux!

Nginx Installation for Linux

Installing from Source

Run the following command to install the Nginx dependencies automatically.

From apt - sudo apt-get build-dep Nginx

From yum - sudo yum install pcre-devel zlib-devel openssl-devel

Ensure that you are in the directory where you wish to install NginX.

Run the following command,

wget http://www.nginx.org/download/nginx-1.3.15.tar.gz
tar zxf nginx-1.3.15.tar.gz
cd nginx-1.3.15
./configure --help
make
make install

To start Nginx server

Service nginx start 

Controlling Nginx 

Nginx quick shut down : nginx -s stop 

Nginx smooth shutdown: nginx -s quit

Reload nginx.conf: nginx -s reload

Reopen the log files: nginx -s reopen

Summary

Now we have a basic Nginx server understanding and why it is so popular nowadays. Follow the mentioned command line and use as your requirement.

Please feel free to post your query/comment/feedback.