Using Nginx for load balancing under Windows

Source: Internet
Author: User
Tags nginx load balancing

Nginx ("Engine X") is a high-performance HTTP and reverse proxy server, also a IMAP/POP3/SMTP proxy server. Nginx was developed by Igor Sysoev, the second-most visited rambler.ru site in Russia, which has already run more than 2.5 of the site. Igor release the source code in the form of a BSD-like license. Although still beta, Nginx has been known for its stability, rich feature set, sample configuration files, and low system resource consumption.

What are the features of Nginx load balancing?

If the back of the server one of the bad, it can automatically identify, the more cattle is it good after the Nginx can immediately identify server A and B, if a response time of 3,b response time is 1, then Nginx will automatically adjust the probability of Access B is a 3 times times, truly nginx load balancing.

Here is an example of how nginx can achieve load balancing:
1, the existing 2 servers of the same Web application, access to the addresses are:
s1:192.168.42.226:9091
s2:192.168.42.227:9091
2, here put Nginx in another server C play the role of third-party arbitration, Server C IP is 192.168.42.229
3, download Nginx, http://nginx.org/en/download.html decompression to the E:\nginx directory.
4. Locate the directory E:\nginx\conf\nginx.conf open nginx.conf configuration as follows:

#Specifies the number of work-derived processes (typically equal to twice times the total number of CPUs or sums, such as two quad-core CPUs, the sum of 8) #指定错误日志文件存放路径, the error log level can be selected as "Debug|info|notice|warn|error|crit" # Error_log logs/error.log notice; #指定pid存放路径 #pid logs/nginx.pid; #use epoll;}default_type Application/octet-stream;#set the log format #log_format main ' $remote _addr-$remote _user [$time _local] "$request" ' # ' $status $body _bytes_sent "$http _ Referer "' # '" $http _user_agent "" $http _x_forwarded_for ";Log_format Main'$remote _addr-$remote _user [$time _local]'Log_format Download'$remote _addr-$remote _user [$time _local]''"$request" $status $bytes _sent''"$http _referer" "$http _user_agent "''"$http _range" "$sent _http_content_range "'; Large_client_header_buffers44k;client_header_timeout 3m;send_timeout 3m;tcp_nopush on;#keepalive_timeout 0;Keepalive_timeout $; Gzip_min_length1100; gzip_types text/plain Application/x-javascript text/css application/Xml;postpone_output1460; client_max_body_size 8m;fastcgi_send_timeout -; fastcgi_buffer_size 64k;fastcgi_busy_buffers_size 128k;gzip_http_version1.1; gzip_vary on;#The same machine in the case of multiple nets, routing switching, IP may be different #server localhost:9080 weight=1;Server192.168.42.227:9091max_fails=2fail_timeout=600s;server_name192.168.42.229; CharSet UTF-8;#if access to/img/*,/js/*,/css/* Resources, then directly take local documents, not through squid# expires 24h;Index Index. htmlIndex. htmIndex.aspx;#keep the user's real informationProxy_set_header X-real-ip$remote _addr;#allow client to request maximum number of single file bytes # buffer agent buffers The maximum number of bytes requested by the user, which can be understood to be saved to local and then passed to the user # and back-end server connection timeout time to initiate handshake wait Response timeout # Wait for backend server response time after successful connection # In fact has entered the back end of the queue waiting for processing # back-end server data return time is within the specified time, the backend server must pass all the data # Proxy request buffer This cache interval will save the user's header information altogether nginx rules processing generally as long as can save the head information # ibid. Tells Nginx to save a single use of a few buffer maximum space # If the system is very busy, you can apply for the domestic major Proxy_buffers official recommendation *2#proxy cache the size of temporary filesProxy_next_upstream Error Timeout invalid_header http_500 http_503 http_404;proxy_max_temp_file_size 128m;}#error_page 404/404.html; Location=/50x.HTML {}#}# fastcgi_pass 127.0.0.1:9000;# fastcgi_param script_filename/scripts$fastcgi_script_name;#}#}}}

PS: Sets the virtual machine to be the IP of the configured third-party server and the port that is required to provide load access externally.
5, double-click E:\nginx\nginx.exe file, start Nginx.
6, open the browser to access the Web program, enter the address: 192.168.42.229:9091 to access.
Test for load balancing: Turn off the service refresh browser on S1 to see if you can continue to access, open the service on S1 S2 on the service refresh browser to see if you can continue to access, if you have access to prove that load balancer is configured correctly.
7, the core code has 2 first is upstream localhost {} inside the configuration, the second is the location /{} inside the configuration, in the above nginx.conf file configuration code.

Using Nginx for load balancing under Windows

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.