Introduction to lightweight HTTP server Nginx

Source: Internet
Author: User
Tags http request what is nginx

One, what is Nginx

I believe many readers are very familiar with Apache, similar to Apache, Nginx is a high-performance http and reverse proxy Server software, but also a IMAP/POP3/SMTP proxy server. Nginx (pronounced "engine X") is developed by Russian program designer Igor Sysoev (Igor publishes the source code in the form of a BSD-like license) and can run on Unix,gnu/linux,bsd,mac OS x, Solaris, and In operating systems such as Microsoft windows. With the stable operation of Nginx in many large websites, its stable and efficient features are gradually recognized by more and more users.

Second, why to choose Nginx

1, the similarities and differences between Nginx and Apache

Nginx and Apache, are an HTTP server software, functional implementation of the modular structure design, all support the common language interface, such as PHP, Perl, Python and so on, but also support positive, reverse proxy, virtual host, URL rewrite, compression transmission, SSL encryption transmission. The biggest difference between them is that the Apache processing speed is very slow, and occupy a lot of memory resources, and Nginx is exactly the opposite; in the realization of the function, all of Apache's modules support dynamic, static compilation, and Nginx modules are statically compiled, while Apache support for fcgi is not good, and Nginx support for fcgi is very good, most importantly, in the process of connection, Nginx support Epoll, while Apache does not support, in size, Nginx installation package is only hundreds of k, and Nginx compared to Apache is absolutely leviathan. After understanding the similarities and differences between Nginx and Apache, we basically know the advantages of Nginx as an HTTP server.

2, choose the advantages of Nginx

The advantages of Nginx as an HTTP server are obvious, with many of the performance and benefits unmatched by other Web servers, as described above:

As a Web server, Nginx is highly efficient at handling static files, index files, and automatic indexing.

As a proxy server, Nginx can realize the reverse proxy acceleration without caching and improve the speed of Web site running.

As a load-balancing server, Nginx can directly support rails and PHP internally, as well as HTTP proxy servers for external service. At the same time, it supports simple fault-tolerant and using algorithm to load balance.

In terms of performance, Nginx is developed specifically for performance optimization and is highly efficient in implementation. It employs a kernel poll model that can support more concurrent connections, supports responses to 50 000 concurrent connections, and consumes very low memory resources.

In terms of stability, Nginx has taken a phased resource allocation technique to make the CPU and memory occupancy rates very low. Nginx officials say Nginx maintains 10 000 inactive connections, which only account for 2.5M of memory, so attacks like DOS have virtually no effect on nginx.

In the case of high availability, Nginx supports hot deployments, which are particularly fast, so that you can upgrade the software version or configuration without interruption, even if it is running for months without restarting, and can be run almost 7x24 hours.

3, Nginx module and working principle

The Nginx is composed of the kernel and the module, in which the design of the kernel is very small and concise, and the work done is very simple, only by mapping the client request to a location block (location is a directive in the Nginx configuration, for URL matching), Each of the instructions configured in this location will start a different module to perform the work accordingly.

The Nginx modules are divided into core modules, basic modules and Third-party modules, HTTP modules, event modules and mail modules are core modules, HTTP access modules, HTTP fastcgi modules, HTTP proxy modules, and HTTP The rewrite module belongs to the basic module, while the HTTP upstream Request hash module, notice module, and HTTP Access key module belong to the third party module, and the modules that users develop according to their needs belong to the third party module. It is with so many modules of support, Nginx function will be so powerful.

The module of Nginx is divided into three categories from function, namely:

(1) Handlers (processor module). Such modules directly handle the request, and the output content and modify the headers information and other operations. Handlers processor modules generally can only have one.

(2) Filters (filter module). This kind of module mainly to the other processor module output content modification operation, finally by Nginx output.

(3) Proxies (proxy class module). is the nginx of HTTP upstream and other modules, these modules mainly with back-end services such as fastcgi, such as the operation of interaction, to achieve service agents and load balancing functions.

The following illustration shows the next regular HTTP request and response process for the Nginx module.

In the way of work, Nginx is divided into two modes: single work process and multiple worker process. In single worker process mode, there is a worker process in addition to the main process, the worker process is single-threaded, and in multiple worker process mode, each worker process contains multiple threads. Nginx default to single worker process mode.

Nginx modules are compiled directly into the Nginx and therefore belong to the static compilation method. After starting the Nginx, the Nginx module is automatically loaded, unlike Apache, which first compiles the module to a so file and then specifies whether to load it in the configuration file. When parsing a configuration file, each module of Nginx is likely to process a request, but the same processing request can only be completed by one module.

This article is from the "Technology Achievement Dream" blog, please be sure to keep this source http://ixdba.blog.51cto.com/2895551/778462

See more highlights of this column: http://www.bianceng.cnhttp://www.bianceng.cn/Servers/web/

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.