Nginx入门实践(四)

环境

系统:Windows7
Nginx版本:1.26.2

Nginx负载均衡实现

  1. 实现逻辑
Nginx1:访问入口
Nginx2、Nginx3、Nginx4:组成负载集群
  1. 配置C:\Windows\System32\drivers\etc\hosts文件
新增IP域名映射
127.0.0.1 backend1.com
127.0.0.1 backend2.com
  1. Nginx1配置
http {
	upstream backend {
		server backend1.com:8081;
		server backend2.com:8082;
		server backend3.com:8000 backup;
	}
    server {
        listen       80;
        server_name  localhost;

        location / {
            proxy_pass http://backend;
        }
    }
}
  1. Nginx2配置
http {
    server {
        listen       8081;
        server_name  backend1.com;
    }
}
  1. Nginx3配置
http {
    server {
        listen       8082;
        server_name  backend2.com;
    }
}
  1. Nginx4配置
http {
    server {
        listen       8000;
        server_name  backend3.com;
    }
}
posted on 2024-09-12 14:17  Simle  阅读(3)  评论(0编辑  收藏  举报