In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)05/31 Report--
This article introduces the knowledge of "how to use Nginx reverse proxy and load balancer to build a multi-person test environment". 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!
Realization principle
When we visit a website, the header of user-agent will be included in the request header, such as mozilla/5.0 (macintosh; intel mac os x 10.12; rv:50.0) gecko/20100101 firefox/50.0. This ua can be customized, and many browser plug-ins also support adding custom ua, such as Firefox's user agent swicher plug-in.
As shown in the figure, a custom ua has been added here, and the content has been changed to its own name. Through this ua request website, we can see that the ua has become its own in the request header, which is a logo.
According to this ua, it is judged by nginx that different ua is forwarded to different ports, corresponding to a website directory under each port.
Nginx judges ua
You can get the ua of each request through nginx, that is, the $http_user_agent variable.
For example, in the location domain, you can judge ua and set an identity as follows:
If ($http_user_agent ~ "dashen") {set $flag "01";}
For example, if you decide that the ua content is dashen and set $flag to 01, you can set many such identifiers.
Nginx reverse proxy and load balancing
By judging different ua, we can forward to different machines and ports through reverse proxy, where the same test machine can be forwarded to different ports of this machine, listening to different ports and setting different website directories.
The details are as follows:
Server {listen 192.168.1.251 server 80; server_name * .example.com; index index.html index.htm index.php; charset utf-8; location / {set $flag "00"; if ($http_user_agent ~ "dashen") {set $flag "01";} if ($http_user_agent ~ "mianwo") {set $flag "02";} if ($http_user_agent ~ "bingkuai") {set $flag "03" } if ($http_user_agent ~ "hadoop") {set $flag "04";} proxy_set_header host $host; proxy_set_header x-forwarded-for $proxy_add_x_forwarded_for; if ($flag = "00") {add_header z-server mobile; proxy_pass http://webserver_mobile;} if ($flag = "01") {add_header z-server dashen; proxy_pass http://webserver_dashen; } if ($flag = "02") {add_header z-server mianwo; proxy_pass http://webserver_mianwo;} if ($flag = "03") {add_header z-server bingkuai; proxy_pass http://webserver_bingkuai;} if ($flag = "04") {add_header z-server hadoop; proxy_pass http://webserver_hadoop;}
This configuration proxies different ua requests to different cloud load balancer servers. See the specific load balancer configuration below.
Nginx load balancing configuration
Several load balancer configurations are defined here, and each load balancer configuration is actually equipped with only one machine, that is, a different port on the local machine.
Upstream webserver_mobile {server 127.0.0.1:8900 max_fails=2 weight=2 fail_timeout=10s;} upstream webserver_dashen {server 127.0.0.1:8901 max_fails=2 weight=2 fail_timeout=10s;} upstream webserver_mianwo {server 127.0.0.1:8902 max_fails=2 weight=2 fail_timeout=10s;} upstream webserver_bingkuai {server 127.0.0.1:8903 max_fails=2 weight=2 fail_timeout=10s;} upstream webserver_hadoop {server 127.0.0.1:8904 max_fails=2 weight=2 fail_timeout=10s;}
So, it's not over, the next thing you need to do is to configure multiple nginx virtual hosts like a normal website. The difference is that you need to listen to several different ports, you need several virtual host configurations, but the website directory is different, such as ua is dashen, the corresponding website directory is / vhosts/example.com/dashen, such as ua is mianwo, the corresponding website directory is / vhosts/example.com/mianwo.
In this way, different testers pull branches under the website directory corresponding to their ua, configure their own ua through browser plug-ins, and realize that multiple people pull different branches on the same machine at the same time, and access the same domain name, separate the website root directory according to different ua, and do not affect each other.
This is the end of the content of "how to use Nginx reverse proxy and load balancer to build a multi-person test environment". 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.
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.