Home > Operation and Maintenance > Nginx > How to configure nginx files when doing load balancing

How to configure nginx files when doing load balancing

(*-*)浩
Release: 2019-11-20 09:41:30
Original
3344 people have browsed it

How to configure nginx files when doing load balancing

As shown in the figure below, the following architecture is our demo structure today. There are two servers in the backend, node1 and node2, and a web server in the frontend. Then Perform load balancing on the web server and direct the front-end access traffic to the two back-end node servers.

The IP addresses of the three servers are: According to this architecture, the websites that need to be accessed are allocated and configured on the back-end node1 and node2 nodes. Then, in order to facilitate testing, we changed the homepages of the two websites to the following content. As shown in the figure below, it is easy to distinguish the visited nodes.

How to configure nginx files when doing load balancing

After the two back-end nodes are configured, we will

configure the load balancing configuration in the web server. First use the default To configure, first open the /etc/nginx/nginx.conf configuration file and add the upstream block content in the http block How to configure nginx files when doing load balancingAs shown in the figure below, and

Configure two backend servers and backend load balancing The name of the cluster is backend. Make a note of this name.

How to configure nginx files when doing load balancing

and then open the /etc/nginx/conf.d/default.conf configuration file. In the server block, change the content in location to the content shown in the second picture below. That is, all traffic accessing 192.168.1.210 is proxied to the backend cluster of the backend. How to configure nginx files when doing load balancing

After the configuration file is configured, use the nginx -t command to test the configuration file to ensure that the configuration file is in ok status, and then execute the nginx command to start the nginx server. How to configure nginx files when doing load balancing

After startup, enter the IP address of the front-end web server 192.168.1.210 in the browser, and then you can see that node1 responded for the first time, and then after refreshing, it became node2. In this way, the load balancing effect is achieved. The two servers respond separately because the default load balancing algorithm is a polling algorithm, that is, the two nodes take turns.

The above is the detailed content of How to configure nginx files when doing load balancing. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template