Intro to Nginx Web Server (Part 1)
Introduction
Today we will be covering Nginx, an open-source software web server and main alternative/competitor to Apache HTTP Server. Nginx has been gaining in popularity since its inception and is used across a wide spectrum of applications for web serving, reverse proxying, caching, load balancing, media streaming, and much more.
the Nginx like “engine-ex” is open source project that can provide management reserve proxy, HTTP cache,and load balancer Nginx is more preference than other web service because the Nginx made because solution problem ,and the problem says how I can connect 10000 concurrent connections
Today is no limit on the number of connections that are being made within the network. To overcome this problem, Nginx was introduced with an event-driven and asynchronous architecture, which is entirely different from the traditional process-driven architecture. This is why Nginx is considered to be the most reliable server that maintains speed and scalability.
Earlier, Nginx functioned for HTTP web serving. But it has evolved since then, and now it also serves as a Reverse proxy, HTTP load balancer, media streaming, and email proxy for IAMP, POP3, and SMTP. Nginx is one of the preferred web servers by many websites dealing with high traffic due to its ability to handle massive connections with astonishing speed. It comes into the market as a significant competitor to the Apache HTTP server.
all parts of Nginx Articles :
- you are in the part one of the Nginx Series
- Installing Nginx And Managed By Command (Part 2)
- Nginx File Configuration and Logs (Part 3)
how does Nginx work?
Nginx is built to offer lower memory usage and high concurrency
and the Nginx creates a new process for each web request
the Nginx uses an asynchronous, event-driven approach, where requests are handled in a single thread
the Nginx has one master process that can control multiple processes, and the master will maintain the worker process
and the worker process will do the actual job
Nginx will each process without any block because that works as an asynchronous.
Nginx deeply :
the Nginx provides no limit of the number of connections the event-driven work with this concept.
- asynchronous
- event-driven approach
the Nginx considers the most web service maintenance, speed, and scalable.
was manufactured Nginx to work with HTTP requests just, but now it can provide the following services
- Reverse proxy
- HTTP load balancer
- media streaming
- email proxy for IAMP, POP3, and SMTP
NGINX Work:
Nginx is a web service that provides HTTP requests but can provide Reverse proxy and another service
nginx can be handling multiple networks terrific at the same time because it works as an asynchronous architecture
nginx can help to secure connection between your data and when to receive the network
now what is nginx advantage
- The written code base is more consistent than other alternatives.
- It provides a friendly configuration format and has a modern design than any other web server alternative.
- It is event-based and allows you to handle multiple connections without having overhead due to context switching.
- It uses less memory and resources.
- NGINX makes the website faster and helps them to get a better Google ranking.
- It shows compatibility with commonly-used web applications like ruby, python, Joomla, etc.
- It helps in transforming the dynamic content to static content.
- It helps in handling thousands of concurrent connections at the same time.
but every advantage also has disadvantages
- It comes with small community support as compared to Apache but has more use cases than Apache.
- It does not offer you many modules and extensions as compared to Apache.
- Due to small community support, it is less like to be preferred
How NGINX work With Request:
in this section, I will write a simple configuration to explain how the request handling, and in the next article I will explain how we can install Nginx.
The NGINX configuration file must include at least one server directive to define a virtual server. When NGINX processes a request, it first selects the virtual server that will serve the request.
A virtual server is defined by a `server` directive in the `http` context, for example :
server {
}
Let’s start with a simple configuration where all three virtual servers listen on port *:80:
server {
listen 80;
server_name example.org www.example.org;
...
}
server {
listen 80;
server_name example.net www.example.net;
...
}
server {
listen 80;
server_name example.com www.example.com;
...
}
in the above configuration all the servers listen to port 80 but with different domains, if coming any request without any domain existing will handling in the first server by default Nginx will set the first server as a primary server but we can change it if write this config near a server section default_server look at the following configuration to see how you can set default_server.
server {
listen 80 default_server;
server_name example.org www.example.org;
...
}
The default_server parameter has been available since version 0.8.21. In earlier versions the default parameter should be used instead.
but if the request comes without any server_name, what we can do.
for this case, we can define the new server in a config file to catch any request coming without server_name.
we can define it as the following configuration
server {
listen 80;
server_name "";
return 444;
}
Conclusion:
we can conclude from all the above when coming to Nginx any request will review the config file to handle a request and go to the correct path and port.
and we see how we can define the server in the config Nginx file.
and we know why we need to use Nginx?
in the next article, I will install Nginx in your server to handle your application.
all parts of Nginx Articles :
- you are in the part one of the Nginx Series
- Installing Nginx And Managed By Command (Part 2)
- Nginx File Configuration and Logs (Part 3)
don’t forget to clap on the articles and you can clap 50 times on each article.
References:
https://docs.nginx.com/nginx/admin-guide/web-server/web-server/