Overview of NGINX

Tram Ho

overview

You have been in the case, you have created a nice Web application that you want to share for everyone to use for commercial purposes or simply public for the group you use, … and you think of finding a Web server for hosting it. You search Google search results for a bunch of web servers Apache HTTP Server, Nginx, IIS, Google Server, … you are bewildered so which one to choose in this article I introduce you to NGINX. Let’s find out

Your application may consist of many static files – HTML, CSS and JavaScript, a backend serving APIs or even multiple webservice. NGINX may be what you are looking for and there are several reasons for that.

I. What is NGINX?

NGINX is a powerful web server and uses a single threaded, event-driven architecture so it is more efficient than Apache server if configured correctly. It can also do other important things, such as load balancing, HTTP caching, or use as a reverse proxy.

II. How does NGINX work?

Before learning more about NGINX, let’s see how the web server works. When a user opens a website, the browser connects to the server of that website. The server then looks for the requested file for the page and sends it to the browser. This is just the simplest type of request.

How NGINX works

NGINX is built to provide low memory usage and high concurrency. Instead of creating new processes for each web request, NGINX uses an asynchronous event-driven approach in which requests are processed in a stream.

Some common features seen in NGINX include:

Reverse proxy with IPv6 cache Load balancing FastCGI Support with WebSockets caching Processing static files, index files and automatically indexing TLS / SSL with SNI Comparison NGINX and Apache

By reading this, many of you will ask why Apache is not another web server, the simplest answer to this question because Apache ranks first in the ranking of the most popular web servers. according to the figures of W3Techs (1/3/2020) with 39.4% and NGINX right behind with 31.8%

Basic architecture

Apache is configured in a “prefork” fashion: that is, how many requests, there are so many processes (whether that request is an image request, a .txt file or a .php script. Of course with static files (.txt files, files .css or image files) are also created by Apache to process the node, so Apache consumes a lot of system resources.

Meanwhile, NGINX is configured in an asynchronous manner: meaning that a NGINX process can handle multiple requests continuously, based on the remaining amount of system resources.

Thanks to such a configuration, NGINX can “embed” programming files (such as .php) into its own process. This means that every request for data is done by a separate process of NGINX, and returned data to the client by reverse proxy.

In addition, for static files (.txt files, .css files or image files), NGINX will return data without the intervention of server side modules.

III. Is Nginx faster than Apache?

The answer is not really. Because it depends on your “fast” definition. Naturally, it cannot be faster than your allowed network speed. But it will be faster in the case of:

Load static files faster: As mentioned, NGINX will load static files without the help of server side modules. Withstand many continuous requests: because of “asynchronous”, NGINX tries its best not to ignore any requests. (While Apache only receives a predefined number of requests, and eliminates the rest.)

So if you define “fast” as “the number of users that constantly request (both requests to static and dynamic files) that the server can handle” then the answer is yes.

Above briefly on NGINX, in the next section I will go into the installation and configuration of NGINX. If you find NGINX suitable for your server selection criteria, please read the next section.

IV. References

Share the news now

Source : Viblo