Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Analysis of Nginx load balancing configuration example

2025-01-30 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)05/31 Report--

This article introduces the relevant knowledge of "Nginx load balancer configuration instance analysis". In the operation of actual cases, many people will encounter such a dilemma. Next, let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!

[implement function]

1. Configure three servers

2. Deploy the same service code on three servers

3. Use nginx to achieve load balancing

[realization idea]

Our nginx load balancer will be deployed on an interactive server, configure connections to the other two servers, all requests directly access the nginx service interface, and then the nginx load balancer will choose the actual server port to call.

[development and deployment environment]

Development environment: windows 7 x64 sp1 English version

Visualstudio 2017

Deployment environment: Ali Cloud ecs instance windows server 2012 x64

Iis 7.0

[required technology]

Asp.net webapi2

[implementation process]

Use asp.net webapi2 to write an interface that simply returns json. To show that we are calling interfaces on different servers, we generate three interface services digitally and deploy them to the iis of the three servers.

Public ihttpactionresult gettest () {/ / throw new exception_dg_internationalization (1001); string ip = request.getipaddressfromrequest (); return ok ("test api. Client ipaddress is->" + ip+ "the server is = 333 =");}

The number behind the three servers I deployed is 111222333.

Note: return ok is a custom return format. You can directly return json () the simple code.

Request.getipaddressfromrequest (); is my extended method to obtain the ip address. Please implement it according to your own situation.

[system testing]

We generate three background codes and deploy them to three servers.

In order to keep the server information confidential, all of my ip addresses below will be identified by ip_a,ip_b,ip_c.

The third is the server on which we will deploy nginx:

After deployment, we configure nginx:

Download nginx:

Then extract it to the ip_c server and open nginx.conf under the conf folder

The editing content is as follows

Then we start the service:

The cmd command changes to the root directory of nginx

In this way, the service is started. Complain, why not prompt a service to start successfully.. Hey, it's not human!

Then we open any interface test tool and execute the same request three times:

Request 1.

Request 2.

Request 3.

It can be found that each time we call the backend service interface is not the same, which ensures that when a large number of customers visit the same server address, the pressure of one server can be shared among several servers, thus achieving the goal of load balancing.

This is the end of the content of "Nginx load balancer configuration instance Analysis". Thank you for reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report