Nginx Load Balancing

Source: Internet
Author: User
Tags openssl rsa openssl x509 nginx load balancing

Nginx load Balancing 1, Nginx load Balancing overview

With the explosive growth of Internet information, load balancing (load balance) is no longer a very unfamiliar topic, as the name implies, load balancing is to distribute load to different service units, not only to ensure the availability of services, but also ensure that the response is fast enough to give users a good experience. Fast-growing traffic and data flow have spawned a wide range of load-balancing products, and many professional load-balancing hardware provides good functionality, but is expensive, which makes load-balancing software popular, and Nginx is one of them.

Nginx not only as a powerful Web server, but also as a reverse proxy server, and Nginx can also follow the schedule rules to achieve dynamic, static separation of the page, you can follow polling, IP hash, url hash, weight and other ways to load balance the backend server, It also supports health checks for back-end servers.

2, Nginx load Balancing implementation

Nginx Load Balancer Implementation environment, Windows Server R2;
You first need to download the Windows Installer from the official website, http://nginx.org/en/download.html
After downloading, unzip, open the cmd command line, enter the Nginx current directory.

2, 1 The HTTP configuration of the Nginx environment 2, 1, 1 configuration steps

First step: Execute command, start Nginx
Turn on the service, open the browser, enter 127.0.0.1, you will be prompted to see the following interface:


Figure 1
If you do not see this interface, please check (nginx Load Balancing FAQ).
The above is native access, you need to test load balancing also need to add the following command:

Server localhost{
Ip_hash;
Server 192.168.0.120:80 weight=11 max_fails=2 fail_timeout=600s;
Server 192.168.0.47:80 weight=1 max_fails=2 fail_timeout=600s;
}
Before adding the above command to the server node, the server is cluster node one.

2, 1, 2 configuration effect
Figure 2

Figure 32, 2 the HTTPS configuration in the Nginx environment 2, 2, 1 configuration steps because HTTPS will have a certificate exists, so need to use the OpenSSL
First step: Download OpenSSL (Windows Installer);
The second step: Open the bin/under the Openssl.exe;
The third step: in obtaining the certificate, the certificate format xx.pfx;

Fourth step: Use OpenSSL for certificate conversions:
The Certificate Conversion command is as follows:
OpenSSL pkcs12–in server.pfx–nodes–out Server.pem
OpenSSL rsa–in server.pem–out Server.key
OpenSSL x509–in server.pem–out server.crt

Fifth step: Copy the certificate server.crt and Server.pem just exported to the Nginx conf directory;

The sixth step: above Nginx configuration:
Open nginx.conf and add the following command below the server node:
Listen 443 SSL;
Ssl_certificate SERVER.CRT;
Ssl_certificate_key Server.key;
Ssl_session_timeout 5m;
Ssl_ciphers high:! anull:! MD5;
2, 2, 2 configuration effect
Figure 4
After you see this page, you need to click "continue to this website (not recommended)"

Figure 5
3, Nginx load Balancing answer

Q: The page is garbled. A: The encoding format of the Web page is different from the Nginx format, in the Nginx configuration to set the encoding format, add under the server node (charset UTF-8; Q: Why is there no effect after each configuration change?). A: After each configuration change, you need to restart Nginx, the command is as follows: Nginx.exe-s Reload Q: Why is it not possible to load balance after configuring upstream localhost? A: Add a command below the location node: proxy_pass http://localhost, where localhost is the same as the name behind upstream, here represents the name of the service, as long as the same is possible. Q: Clearly set different weights, why does the load balancer not occur? A: When the weight is set, due to the weight is not a big difference, so it is not so obvious, the more powerful server is assigned to the task of the probability is relatively large, if you need to see the effect, you can set a large difference in weight, so you can quickly see the effect. Q: Nginx start error
Nginx start error under win7,win2008: Bind () to 0.0.0.0:80 failed (10013:an attempt is made to access a socket in a-mode forbidden by I TS access permissions). A: The reason is that Windows Nginx default 80 port is occupied by the system, resulting in Nginx start error solution. Run Netstat-aon under cmd | findstr:80 See if Port 80 is occupied. WORKAROUND: 1, open the registry: Regedit2, find: HKEY_LOCAL_MACHINE\SYSTEM\CURRENTCONTROLSET\SERVICES\HTTP3, find a REG_DWORD type of entry start, Change it to 04, reboot the system, and the systems process will not consume 80 port restarts after start Nginx.exe. In the browser, enter 127.0.0.1 to see the dear "Welcome to nginx!".







Nginx Load Balancing

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.