CentOS7 Nginx Load Balancer

Source: Internet
Author: User
Tags php server custom name nginx server nginx reverse proxy

Five Servers192.168.155.129nginx Reverse proxy Server192.168.155.130 apache+php Server, PHP to use the MySQL function library, configuration will specify the MySQL installation path, so although later connected to the remote MySQL server, When you install PHP, you should also install MySQL to provide MySQL library (just use the library, no need to start the database and assign account), the following nginx+The same is true for PHP servers192.168.155.131 nginx+PHP Server192.168.155.132 apache+php+MYSQL1 Server192.168.155.133 apache+php+mysql2php Server The IP address of this nginx server is192.168.155.129192.168.155.129shell terminal temporarily closed Nginxservice nginx stop in http{} node add upstream mySite {server192.168.155.130:80Down ; Server192.168.155.131:80 weight=1; Server192.168.155.132:80 weight=2; Server192.168.155.133:80backup; #Ip_hash;}upstream represents a set of load balancer servers, MySite is a custom name used to assign the following proxy_pass parameter down to indicate that the server is temporarily not participating in the load weight The default is 1,weight, the load weights are greater. The above proportional words quite access two times 192.168.155.132, visit once 192.168.155.131Backup machine is requested when all other non-backup machines are down or busy. So the pressure on this machine is the lightest. Ip_hash let each client access fixed access to the first access to the back-end server, this method has some drawbacks, temporarily commented out in the need to use the payload of the server{} node need to use the load of location{} to add the following segment Proxy_pass HTTP://MySite;the server{} node starts using the group server to do load balancing the reverse proxy will send the client request over the URL, parameters, and so on to a load-balanced server processing, if there is a machine failure, will automatically transfer to other machine processing nginx support multiple groups of load balancing ,You can configure multiple upstream to serve different servers. Nginx's upstream currently supports4load distribution in different ways1), polling (default is equivalent to Weight=1each request is individually assigned to a different back-end server in chronological order, and can be automatically rejected if the backend server is down. 2), weight specifies the polling probability, the weight value is proportional to the access ratio, and is used in cases where the performance of the backend server is uneven. 2), ip_hash each request according to the hash result of the access IP allocation, so that each visitor fixed access to a back-end server, you can solve the problem cannot be shared session. 3), fair (third-party) assigns requests in response time to the backend server, with a short response time priority allocation. 4), Url_hash (third party) Vim/usr/local/nginx/conf/nginx.conf Open Server service Nginx start new F1 in MySite group per server root directory.PHP per Server F1.PHP content is sequentially192.168.155.130/f1.PHP<?phpEcho"This is 192.168.155.130";Exit;? >192.168.155.131/f1.PHP<?phpEcho"This is 192.168.155.131";Exit;? >192.168.155.132/f1.PHP<?phpEcho"This is 192.168.155.132";Exit;? >192.168.155.133/f1.PHP<?phpEcho"This is 192.168.155.133";Exit;? >enter HTTP in the browser://192.168.155.129/f1.phpThe output displays this is192.168.155.131or this is192.168.155.132two times per display this is192.168.155.132 display once this is 192.168.155.131

CentOS7 Nginx Load Balancer

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.