In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-22 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/01 Report--
How to configure Nginx load balancing in WebApi? In view of this problem, this article introduces the corresponding analysis and answers in detail, hoping to help more partners who want to solve this problem to find a more simple and feasible way.
01PARTCoreWebApi tutorial local demo environment
Visual Studio2019-Vsersion:16.4.4 + NetCore3.1.2
02PARTNginx quickly builds and configures load balancers
Nginx is a lightweight Web server / reverse proxy server and email (IMAP/POP3) proxy server, distributed under the BSD-like protocol. It is characterized by less memory and strong concurrency ability. in fact, the concurrency ability of nginx performs better in the same type of web server. Chinese mainland uses nginx website users: Baidu, JD.com, Sina, NetEase, Tencent, Taobao and so on.
Let's demonstrate the process of configuring Nginx
1. Download Nginx package: http://nginx.org/en/download.html Note: the path for downloading and storing Nginx package must be in English; it cannot contain Chinese characters.
two。 Start Nginx: directly to the downloaded Nginx package, double-click to open "nginx.exe", or you can start it through the command; the command startup is not detailed here; after startup, open the task manager, you will find that there will be Nginx services in the task manager
3. At this point, you can use Nginx to configure load balancing. I first start multiple WebApi servers and run them, and the data returned by the same interface of each server is slightly different; the data returned by the interface of the first server is: day and night education-1, the data returned by the interface of the second server is: day-and-night education-2, and the data returned by the interface of the third server is: day-and-night education-3 The ports of the three servers after startup are: 8011 8022 8033; that is to say, port 8011 returns: day and night education-1; port 8022 returns: day-and-day education-3; that is to say, the codes of the three servers are the same, and the results returned here are different in order to be able to test the difference.
4. After startup, the debugging result is:
Http://127.0.0.1:8011/api/First returns: day and night education-1
Http://127.0.0.1:8022/api/First returns: day and night education-2
Http://127.0.0.1:8033/api/First returns: day and night education-3
Figure 1
Figure 2
Figure 3
5. The test shows that all three services have been started: at this point, I will configure the three server bronze drum nginx clusters; configure the configuration file
Figure 4
Modify the configuration file as follows:
CMD executes the nginx-s reload command, reloads the service, and tests as follows:
6. Request the same address: http://127.0.0.1:8080/api/First gets three different results three times
Figure 1
Figure 2
Figure 3
This is the answer to the question on how to configure Nginx load balancer in WebApi. I hope the above content can be of some help to you. If you still have a lot of doubts to be solved, you can follow the industry information channel for more related knowledge.
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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.