This is the 15th day of my November update Challenge, the last Update Challenge of 2021
The previous articles covered nGINx load balancing and some strategies for load balancing. And four – layer load balancing and seven – layer load balancing. This article will share a case study of the previous overview of seven-layer load balancing. This section describes layer-7 load balancing based on the configuration file. This is also a summary of the entire nginx article. I hope you can put forward the wrong place for writing, I will correct. thank you
Case 1: Load balancing with general polling rules for all requests
upstream backend{
server 192.168.1.100:9001;
server 192.168.1.100:9002;
server 192.168.1.100:9003;
}
server {
listen 8083;
server_name localhost;
location/ {proxy_passhttp://backend; }}Copy the code
Case 2: Load balancing with weighted polling rules for all requests
upstream backend{
server 192.168.1.100:9001 weight=7;
server 192.168.1.100:9002 weight=5;
server 192.168.1.100:9003 weight=3;
}
server {
listen 8083;
server_name localhost;
location/ {proxy_passhttp://backend; }}Copy the code
Case 3: Load balancing for specific resources
upstream videobackend{
server 192.168.1.100:9001;
server 192.168.1.100:9002;
}
upstream filebackend{
server 192.168.1.100:9003;
server 192.168.1.100:9004;
}
server {
listen 8084;
server_name localhost;
location /video/ {
proxy_pass http://videobackend;
}
location /file/ {
proxy_passhttp://filebackend; }}Copy the code
Case 4: Load balancing for different domain names
upstream itcastbackend{
server 192.168.1.100:9001;
server 192.168.1.100:9002;
}
upstream itheimabackend{
server 192.168.1.100:9003;
server 192.168.1.100:9004;
}
server {
listen 8085;
server_name www.itcast.cn;
location / {
proxy_passhttp://itcastbackend; }}server {
listen 8086;
server_name www.itheima.cn;
location / {
proxy_passhttp://itheimabackend; }}Copy the code
Case 5: Implementing load balancing with URL rewriting
upstream backend{
server 192.168.1.100:9001;
server 192.168.1.100:9002;
server 192.168.1.100:9003;
}
server {
listen 80;
server_name localhost;
location /file/ {
rewrite ^(/file/.*) /server/The $1 last;
}
location / {
proxy_passhttp://backend; }}Copy the code
The above cases are my introduction to the seven-layer load balancing, and I hope you can put forward valuable suggestions after reading the bad and wrong places. thank you