Nginx study notes (a) - Overview

A, Nginx Overview

1.1 What is Nginx?

Nginx (engine x) is a lightweight, high-performance HTTP server and reverse proxy web server, but also provides IMAP / POP3 / SMTP services.Nginx is the lgor Sysoevdesign and development of Russia visited the second rambler.ru site. From 2004 release date, with the power of open source, and we are approaching maturity and perfection. Nginx stability, feature set, sample configuration files and low system resource consumption to let him catch up with 12.18 percent of the global use rate active site, about 22.2 million sites.

Nginx features: possession of less memory, high concurrency

1.2 Why Nginx?

(1) cross-platform, easy configuration;

(2) non-blocking, high concurrent connections: processing 2-3 million concurrent connections, the official monitor can support 50,000 concurrent;

(3) Memory consumption is small: turn 10 before accounting for nginx 150M memory, Nginx has taken a phased resource allocation techniques;

Good (4) nginx static files, consume less memory;

(5) Built-in health check function: if a server goes down, will do a health check, and then send the request will not be sent to the server downtime. Re-submit the request to other nodes.

(6) Save Broadband: support GZIP compression, you can add a local browser cache;

High (7) Stability: very small probability of downtime

(7) master / worker structure: a master process, generate one or more worker process.

(8) receiving a user request is asynchronous: the browser sends a request to the server nginx, it first receives a user request all down, and then sent to the backend web server disposable, greatly reduces the pressure on a web server;

(9) while receiving the web server returns the data, while transmitted to the client browser;

(10) low dependency network, as long as the ping can load balancing;

(11) can have multiple nginx server;

(12) Event-driven: the communication mechanism using epoll model.

1.3 Nginx operating mode

1、Nginx by the kernel and the module.

  • Core design is very small and simple, the work done is very simple. Lookup profile only by the client request is mapped to a location Block (Nginx instruction location is a configuration for matching URL), and each instruction in this location will be configured in different modules to complete startup respective work.
  • Nginx modules into the core module from the structure, the foundation modules and third-party modules:
    Core Module: HTTP module, EVENT module MAIL module and
    base modules: HTTP Access module, HTTP FastCGI module, HTTP Proxy module and HTTP Rewrite module,
    third party module: HTTP Upstream Request Hash module, Notice modules and HTTP Access Key modules.

2、Nginx has two operating modes: master-worker模式and 单进程模式.

master-worker pattern: a master process and at least one worker process

In this mode, nginx after a successful start, there will be a master process and at least one worker process. Used for the production environment.

  • master 进程Responsible for processing the signal system, load the configuration, management worker process (start, kill, monitoring, sending messages / signals, etc.).

  • worker 进程Responsible for handling specific business logic, that is, on the outside, the real service is worker process.

1. High stability, as long as there is worker process alive, able to provide service and a worker process hangs master process will immediately start a new worker process to ensure that the same number of worker processes, reduce the probability of service interruption.
2. cpu affinity with the configuration of linux, you can take full advantage of multi-core cpu, improve performance
3. Signal processing / configuration reloads / upgrades can be done as little as possible or without service interruption (hot restart -> not interrupt service )

Here Insert Picture Description
Single-process mode: only one process

Single-process mode, nginx start after only one process, all of the work by nginx responsible for this process.
Since only one process, so you can easily use gdb debugging and other tools.
This mode does not support nginx smooth upgrade feature, any signal processing can cause service interruptions, and because it is a single process, the process hangs, in the absence of external monitor can not restart the service.
Therefore, this model is generally used only in the development stage and debugging is not used in a production environment. (To understanding)

1.4 Nginx applications

  • Reverse Proxy:

Reverse proxy (Reverse Proxy) mode refers to the proxy server to accept connection requests on the internet, and then forwards the request to the server on the internal network, and returns the result obtained from the server to the client on request internet connection, At this point the external proxy server on the performance of a reverse proxy server. Simply put, the real servers can not directly access the external network, so you need a proxy server, and proxy server can simultaneously access the external network of any connection with the same real server in a network environment, of course, may be the same server, port is different.

  • Load Balancing:

Nginx provide load balancing strategy there are two kinds: built-in policies and expansion strategies. Built-in policies for the poll, weighted round-robin, Ip hash.

  • Http Server

Nginx is itself a Server static resources. When only static resources, you can use the server Nginx to do, but now also popular movement separation can be achieved by Nginx.Static and dynamic separation is to make dynamic websites where dynamic pages according to certain rules to distinguish the same resources and often becomes a resource area, movement of resources to do after the split, we can according to the characteristics of static resources to do the cache operation, this is the core idea of ​​the site static process.

  • Forward Proxy

Forward proxy server means is located between the client and the origin server (origin server), in order to obtain the content from the origin server, the client transmits a request to the proxy and specify the destination (origin server), and then forwarded to the origin server agent the content of the request and get back to the client, the client can use the forward proxy.

Published 102 original articles · won praise 21 · views 5335

Guess you like

Origin blog.csdn.net/ranrancc_/article/details/102657684