Discussion on Nginx

Source: Internet
Author: User

First, what is Nginx

The official Nginx site is described in this way (nginx.org):

NGINX is a free, Open-source, high-performance HTTP server and reverse proxies, as well as a IMAP/POP3 proxy server. NGINX is known for it high performance, stability, rich feature set, simple configuration, and low resource consumption.


NGINX is one of a handful of servers written to address the c10k problem. Unlike traditional servers, NGINX doesn ' t rely on threads to handle requests. Instead it uses a much more scalable Event-driven (asynchronous) architecture. This architecture uses small, but more importantly, predictable amounts of memory under load. Even if you don't expect to handle thousands of simultaneous requests, can still benefit from NGINX ' s high-performance and small memory footprint. NGINX Scales in all directions:from the smallest VPS all the "the" to large clusters of servers.


NGINX powers several high-visibility sites, such as Netflix, Hulu, Pinterest, CloudFlare, Airbnb, WordPress.com, GitHub, S Oundcloud, Zynga, Eventbrite, Zappos, Media Temple, Heroku, RightScale, Engine Yard, MaxCDN and many others.


Getting StartedCommunity3rd party Modulescontributing


Summary:Nginx is rich in functionality, can be used as a Web server, also as a reverse proxy service, IMAP/POP3 reverse proxy server, the ability to quickly respond to static page requests, and support Fastcgi,ssl,url rewrite, gzip, and support a large number of third-party module extensions.


Second, the characteristics of Nginx

1. Adopt modular design, good expansibility;
2. High reliability, nginx based on Master/worker;
3. Support hot deployment, smooth upgrade to new version;
4. Low memory consumption, 10,000 keep-alive connection mode of inactive connection consumes only 2.5M of memory;
5. Support asynchronous non-blocking mode and event-driven model, each process processing multiple requests;
6. Memory Mapping: Direct mapping of content on disk to memory by process memory

Three, NGINX modular structure

NGINX modular structure including core modules, standard modules, third-party modules

Core module: The core module is nginx normal operation indispensable module, mainly for Nginx to provide the most basic core modules, including process management, rights management, etc.

Standard module: The modules included in the compilation and installation, including optional HTTP module, mail Service module, etc.

Third-party module: The third party module by the program personnel or the company open source self-research module; Nginx site third-party module address: https://www.nginx.com/resources/wiki/modules/

Four, Nginx server process

The Nginx service process is divided into three main categories:

1:master main process: main function of main process to manage internal other processes and smooth upgrade functions

2:worker worker process: generated by the main process, generated quantity can be specified by the configuration file, its main function is used in response to its request

3: Cache related processes are divided into two main categories: 1) Cache loader: Load cache object; 2) cache manager manages cached objects


Five, the Web request processing mechanism of Nginx server

Nginx adopts asynchronous non-blocking and event-driven model in processing the request;

Specific process

When a worker process receives a request sent by the client, calls IO for processing, if the result is not immediately available, puts the request into a list of pending events, invokes the "event handler" in a non-blocking IO manner to process the request, and the event-driven model allows the worker process to process multiple requests simultaneously. There is no need to worry about IO specifics, the specific invocation of IO is entirely managed by the event-driven model. When the IO call is complete, the worker process event is ready, and when the worker process receives a notification, it temporarily suspends the current processing transaction to respond to the client's request.

The event processing library has also been multiplexed, the most common of which are the following three types; select;poll;epoll

The Epoll library is recognized as the best event-driven model, and the Epoll library creates a list of events with n descriptors by invoking the notification kernel, and then sets the events of interest to those descriptors and adds them to the list of kernel events. For other event-handling models, see the "event-driven model type" attached to this article;

The use of asynchronous non-blocking and time-driven models reduces the blocking delays and process-consuming pressures on the IO calls of the worker process. Greatly accelerates the response and processing capability of Nginx.

Vi. installation and use of Nginx


1. Install the development package

Yum install-y "Development Tools"

2. Resolve Dependencies

Yum install-y pcre-devel openssl-devel zlib-devel

    • Pcre-devel for URL Rewrite, need to use to regular expression

    • Zlib-devel to provide data transfer to support compression

    • Openssl-devel to support HTTPS

3. Create user

Create a System user Nginx

Useradd-r Nginx


4, prepare the source package:

wget http://nginx.org/download/nginx-1.8.0.tar.gz

5. Installation

1) Unzip

TAR-XF nginx-1.8.0.tar.gz

2) Check the installation environment and customize the installation module and generate makefile

./configure--prefix=/usr/local/nginx--conf-path=/etc/nginx/nginx.conf--error-log-path=/var/log/nginx/error.log --http-log-path=/var/log/nginx/access.log--pid-path=/var/run/nginx.pid--lock-path=/var/run/nginx.lock--user= Nginx--group=nginx--with-http_ssl_module--with-http_v2_module--with-http_dav_module--with-http_stub_status_ Module--with-threads--with-file-aio

Note: CentOS 6 does not support HTTP_V2

3) Compile dependent source code, generate all relevant target files

Make

4) Install the executable program

Make install

5) Create the execution environment

/etc/profile

Export Path=/usr/local/nginx/sbin: $PATH



6, the start of Nginx service (note: Before this must be turned off the other occupied with the port 80 program)

[Email protected] sbin]# nginx-h

Nginx version:nginx/1.8.0

Usage:nginx [-?HVVTQ] [-s signal] [-c filename] [-p prefix] [-g directives]


Options:

-?,-h:this help Display helpful information

-v:show version and exit show their versions

-v:show version and configure options then exit monitor release information and configuration

-t:test configuration and Exit test config correctness

-q:suppress non-error messages during configuration testing test configurations show only errors

-S signal:send signal to a master process:stop, quit, reopen, reload signal to main process

-P prefix:set Prefix path (default:/usr/local/nginx/) specifies the server path prefix to the file path

-C filename:set configuration file (default:/etc/nginx/nginx.conf) specifies the profile path

-G Directives:set Global directives out of configuration file additional profile path specified


Nginx service startup can execute binary files directly./nginx

Heavy Duty service: Nginx-s Reload



7, the nginx signal mechanism:

reopen log file

smooth upgrade executable

TD width= "423" valign= "Top" style= "border-top:none;border-left:none;border-bottom-width:1px;border-bottom-color:# C0c0c0;border-right-width:1px;border-right-color: #C0C0C0;p adding:3px; " > TD width= "423" valign= "Top" style= "border-top:none;border-left:none;border-bottom-width:1px;border-bottom-color:# C0c0c0;border-right-width:1px;border-right-color: #C0C0C0;p adding:3px; " >
term, int

quick close

quit

calmly close

hup

reload, start a new worker process with a new configuration

user1

user2

WINCH

Gracefully close the worker process

[Email protected] ~]# Ps-aux|grep Nginx

Warning:bad syntax, perhaps a bogus '-'? See/usr/share/doc/procps-3.2.8/faq

Root 3457 0.0 0.0 44628 1756? Ss Oct15 0:00 nginx:master process./nginx

Nginx 11157 0.0 0.0 45072 1792? S 16:58 0:00 Nginx:worker Process

Root 11221 0.0 0.0 103332 860 PTS/2 s+ 17:17 0:00 grep nginx

[Email protected] ~]# kill-quit 3457

[Email protected] ~]# Ps-aux|grep Nginx

Warning:bad syntax, perhaps a bogus '-'? See/usr/share/doc/procps-3.2.8/faq

Root 11225 2.0 0.0 103328 856 pts/2 s+ 17:17 0:00 grep nginx







This article is from the "Notes" blog, so be sure to keep this source http://snowbamboo1.blog.51cto.com/9291858/1866422

Discussion on Nginx

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.