Introduction
Nginx("Engine x") is a high-performance HTTP and reverse proxy server as well as a IMAP/POP3/SMTP server. Nginx was developed by Igor Sysoev for the second rambler.ru site of Russian traffic, and the first public version 0.1.0 was released on October 4, 2004. It publishes the source code in the form of a BSD license, which is known for its stability, rich feature set, sample configuration files, and consumption of low system resources.
installation
Steps: Download Nginx, unzip to the D-disk directory, start the Nginx service.
Official website: http://nginx.org/en/download.html (Note: To select the Windows version when downloading)
Unzip to the D-Packing directory, then start nginx, run cmd execution command:
D:CD Nginxstart Nginx
Nginx Basic command:
Nginx-s Stop//Stop Nginx
Nginx-sreload//Reload configuration file
Nginx-squit//Exit Nginx
Use
Suppose now that Nodejs Express has two site access address: 127.0.0.1:3000 | 127.0.0.1::3001 Configure the default module for load balancing and health detection as follows:
Locate the configuration file (my Nginx installation directory is: D:\nginx): The D:\nginx\conf\nginx.conf setting is replaced with the following code:
http {include mime.types; Default_type Application/octet-stream; Upstream Sample {server127.0.0.1:3000 Max_fails=1 fail_timeout=40s; Server127.0.0.1:3001 Max_fails=1 fail_timeout=40s; KeepAlive64; } Server {Listen80; server_name127.0.0.1; Location/{proxy_http_version1.1; Proxy_set_header Upgrade $http _upgrade; Proxy_set_header Connection ' upgrade '; Proxy_set_header Host $host; Proxy_cache_bypass $http _upgrade; Proxy_pass http:sample/; Proxy_connect_timeout1; Proxy_read_timeout1; } }}
Now the access address 127.0.0.1,nginx will be rotated to distribute the request to Port 3000 and port 3001 respectively.
If one server is hung up, it will be assigned to another server until it detects the normal access of the paralyzed server and resumes the task of rotating the requested distribution.
Windows platform using Nginx configuration Nodejs Program