Load balancing for application of Ngnix proxy module

Source: Internet
Author: User


Load balancing for application of Ngnix proxy module


Proxy Module Introduction

As mentioned in my previous article, Nginx can provide reverse proxy acceleration, application-level load balancing, and the ability to back-end
The server does the health state detection. Let's take a look at how to achieve the above functions.



Experimental environment


Host Name Key Features Extranet Address Intranet address
Code Nginx Proxy Server 192.168.1.11 192.168.10.1
Node1 HTTPD Application Server 1
192.168.10.2
Node2 HTTPD Application Server 2
192.168.10.3


If you have not contacted Nginx before, please read the post I wrote earlier. Nginx compiled installation .


Configure Proxy

First, configure the reverse proxy, and use Node1 and node2 to achieve load balancing.

Configuration on 1.code, editing the configuration filevim /usr/local/nginx/conf/nginx.conf

In the HTTP segment of the master configuration file, use upstream to define a cluster, and the subsequent httpserver is the name of the cluster. Upstream Httpserver {server 192.168.10.2;server 192.168.10.3;} Then use the Proxy_pass setting in location/To delegate all of the user's requests to the load Balancer cluster that you just defined. Location/{proxy_pass http://httpserver;root html;index index.html index.htm;}

Start service: [[email protected] ~]#/usr/local/nginx/sbin/nginx
Restart service: [[email protected] ~]#/usr/local/nginx/sbin/nginx-s Reload

Configuration on the 2.node1

[[email protected] ~]# Yum install httpd-y installation httpd
[[Email protected] ~]# service httpd start start httpd services
[[email protected] ~]# echo "This is Node1 page" >/var/www/html/index.html defines a master page.

Configuration on the 3.node2

[[email protected] ~]# Yum install httpd-y installation httpd
[[Email protected] ~]# service httpd start start httpd services
[[email protected] ~]# echo "This is Node2 page" >/var/www/html/index.html defines a master page. Configure different pages to make it easier for us to differentiate.

4. Open the browser input proxy server address 192.168.1.11 to test:

650) this.width=650; "Src=" http://www.178linux.com/wp-content/plugins/ueditor/ueditor/themes/default/images/ Spacer.gif "alt=" alt text "longdesc=" Http://www.178linux.com/test-1.gif "style=" height:auto;vertical-align:middle; border:0px; "/>650" this.width=650; "src=" http://www.178linux.com/ueditor/php/upload/image/20160327/ 1459067882912441.gif "title=" 1459067882912441.gif "alt=" Test-1.gif "style=" height:auto;vertical-align:middle; border:0px; "/>

You can see that the load balancing is successful.

5. Stop the httpd service above the Node2 and test it.

[[Email protected] ~]# service httpd stop

650) this.width=650; "Src=" http://www.178linux.com/wp-content/plugins/ueditor/ueditor/themes/default/images/ Spacer.gif "alt=" alt text "longdesc=" Http://www.178linux.com/test-2.gif "style=" height:auto;vertical-align:middle; border:0px; "/>650" this.width=650; "src=" http://www.178linux.com/ueditor/php/upload/image/20160327/ 1459067893791981.gif "title=" 1459067893791981.gif "alt=" Test-2.gif "style=" height:auto;vertical-align:middle; border:0px; "/>

When the proxy server detects that the health of the node2 is unhealthy, all subsequent requests are sent to Node1 for response.

6. Start the httpd service above the Node2 and test again.

[[Email protected] ~]# service httpd start

650) this.width=650; "Src=" http://www.178linux.com/wp-content/plugins/ueditor/ueditor/themes/default/images/ Spacer.gif "alt=" alt text "longdesc=" Http://www.178linux.com/test-3.gif "style=" height:auto;vertical-align:middle; border:0px; "/>650" this.width=650; "src=" http://www.178linux.com/ueditor/php/upload/image/20160327/ 1459067897598414.gif "title=" 1459067897598414.gif "alt=" Test-3.gif "style=" height:auto;vertical-align:middle; border:0px; "/>

After the proxy server detects that the health of Node2 is healthy, it loads the user's request to two node.


This article is from the "Earth is Dangerous" blog, please be sure to keep this source http://779834367.blog.51cto.com/7182184/1762249

Load balancing for application of Ngnix proxy module

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.