yungame 2020-04-23
负载均衡建立在现有网络结构之上,它提供了一种廉价有效透明的方法扩展网络设备和服务器的带宽、增加吞吐量、加强网络数据处理能力、提高网络的灵活性和可用性。
user nginx; worker_processes 1; events { worker_connections 1024; } http { include mime.types; default_type application/octet-stream; sendfile on; keepalive_timeout 65; upstream myapp1 { server 192.168.75.145:9090 weight=10; server 192.168.75.145:9091 weight=10; } server { listen 80; server_name nginx.funtl.com; location / { proxy_pass http://myapp1; index index.jsp index.html index.htm; } } }
定义负载均衡设备的 Ip及设备状态 upstream myServer { server 127.0.0.1:9090 down; server 127.0.0.1:8080 weight=2; server 127.0.0.1:6060; server 127.0.0.1:7070 backup; }
在需要使用负载的server节点下添加
proxy_pass http://myServer;