Nginx solves the C10K problem of the server (that is, the number of clients connected within one second is 10k or 10,000). The design of Nginx does not use threads to process requests like traditional servers, but a more advanced mechanism-event-driven mechanism, which is an asynchronous event-driven structure.
Although Nginx currently accounts for only a small part of the market, its high performance and low memory consumption structure make it more and more common. A typical application is that we can use Nginx as a reverse proxy to load balance the website. device. For example: WordPress, GitHub and other well-known websites all use Nginx.
Features of Nginx
Ø Cross-platform: can be compiled and run on most Unix like systems. There is also a ported version for Windows.
Ø The configuration is extremely simple: very simple and easy to use.
Ø Non-blocking, high-concurrency connection: When data is copied, the first stage of disk I/O is non-blocking. The official test can support 50,000 concurrent connections, and in actual production, it can run 20,000 to 30,000 concurrent connections (thanks to Nginx adopting the latest epoll event processing model (message queue).
Ø There is no need for a long connection between the Nginx proxy and the back-end web server;
Ø Nginx receives user requests asynchronously, that is, it first receives all user requests and then sends them to the back-end Web server at once, which greatly reduces the pressure on the back-end Web server.
Ø When sending a response message, it receives data from the back-end web server and sends it to the client.
Ø The network dependency is low. In theory, load balancing can be implemented as long as the ping can be passed, and the internal network and external network traffic can be effectively distinguished.
Ø Support built-in server detection. Nginx can detect whether the server fails based on the status code and timeout information returned by the application server when processing the page, and promptly returns the incorrect request and resubmits it to other nodes.
Ø Adopt Master/worker multi-process working mode
Ø In addition, it has the characteristics of small memory consumption, low cost (much cheaper than F5 hardware load balancer), bandwidth saving, and high stability.
Basic functions of Nginx
The functions of Nginx include basic HTTP functions and extended functions. Like the Apache server, the Nginx server is designed to provide more functions and can effectively extend these functions. Each module provides a function, and function expansion can be achieved by compiling these function modules.
1. Basic HTTP functions
a) Provide static files and index files, process static files, index files and automatic indexing, and open file descriptor cache;
b) Use cache-accelerated reverse proxy, reverse proxy acceleration (no cache), simple load balancing and fault tolerance;
c) Use caching mechanism to accelerate remote FastCGI, simple load balancing and fault tolerance;
d) Modular structure. Filters include gzipping, byte ranges, chunked responses, and SSI-filter. In the SSI filter, multiple sub-requests to the same proxy or FastCGI are processed concurrently;
e) Support SSL and TLS SNI support;
f) IMAP/POP3 proxy function;
g) Use an external HTTP authentication server to redirect users to the IMAP/POP3 backend;
h) Use an external HTTP authentication server to authenticate the user and redirect the connection to the internal SMTP backend;
2. Other HTTP functions
a) Name-based and IP-based virtual servers;
b) Support Keep-alive and pipeline connections;
c) Flexible configuration and reconfiguration, and online upgrade without interrupting customer access processing;
d) Access log format, cache log writing and fast log rotation;
e) 3xx-5xx error code redirection;
f) Speed limit
Basic modules of Nginx
The core modules of Nginx include kernel modules and event-driven modules, namely: CoreModule and EventsModule; there is also a third-party module HTTP kernel module, HttpCoreModule, which is the core module of the Nginx server.
CoreModule and EventsModule modules have fewer configurations than HttpCoreModule, but their configuration will affect system performance rather than functional differences.
1. CoreModule is used to control the basic functions of the Nginx server;
2. EventsModule is used to control how Nginx handles connections. Some parameters of the instructions of this module will have an important impact on the performance of the application system;
3. HttpCoreModule provides HTTP access to the Nginx server. This module is indispensable.
Nginx configuration installation environment
1.yum -y install gcc* epel-release curl curl-devel mcrypt openssl openssl-devel gd gd-devel freetype freetype-devel zlib zlib-devel zip libmcrypt-devel libmcrypt pcre-devel libevent-devel ncurses-devel libxml2* mcrypt* libmcrypt* cmake gcc* lrzsz ntp telnet
2.Create user
useradd -s /sbin/nologin web
3. Create the nginx installation directory (this step can be omitted)
mkdir -p /usr/local/nginx
chown -r web:web /usr/local/nginx
4. Download and install the software installation package from Huajun Software Park (softwaredownload4.com/)
5. Copy the downloaded software package to the /usr/src/ directory
6. Unzip the Nginx installation package
tar -zxf /usr/src/tengine-2.1.2.tar.gz
cd /usr/local/tengine-2.1.2/
7. Carry out testing
./configure --prefix=/usr/local/nginx --with-http_sub_module --with-http_gzip_static_module --with-http_stub_status_module --with-pcre
8.Compile
make
9.Installation
make install
10. Start nginx /usr/local/nginx/sbin/nginx
it works
it works
it works