Windows platform using Nginx configuration Nodejs Program

Source: Internet
Author: User

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

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.