nginx 负载均衡

http负载均衡配置

在http中设置

upstream myapp {

ip_hash;

server 192.168.1.33:80;

server 192.168.1.181:80 weight=5;

}

server {

listen 801 default_server;

server_name example.com;

location / {

index index.html index.htm index.php;

index proxy_set_header Host $host;

index proxy_set_header X-Real-IP $remote_addr;

index proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

proxy_pass http://myapp;

}

}

 

nginx tcp udp负载均衡 udp只是在监听端口后面加上udp

stream {

upstream ssh_proxy {

hash $remote_addr consistent; #一致性hash

server 127.0.0.1:8513 max_fails=2 fail_timeout=2s weight=2; #健康状态检测

server 192.168.1.181:8513 max_fails=2 fail_timeout=2s;

server 192.168.1.159:8513 max_fails=2 fail_timeout=2s;

}

server {

listen 8512;

proxy_connect_timeout 1s; #连接超时

proxy_timeout 20s; #连接超时时间,如果不配置,永远不超时

proxy_pass ssh_proxy;

}

server {

listen 8512 udp;

proxy_connect_timeout 1s; #连接超时

proxy_timeout 20s; #连接超时时间,如果不配置,永远不超时

proxy_pass ssh_proxy;

}

}

详见

https://docs.nginx.com/nginx/admin-guide/load-balancer/tcp-udp-load-balancer/#upstream

你可能感兴趣的:(nginx,nginx,负载均衡)