nginx-tcp负载均衡

概念

官方参考文档:http://nginx.org/en/docs/stream/ngx_stream_core_module.html
只有nginx1.9以上的版本才支持tcp负载均衡
配置必须出现在main段,不能配置在http,event和server标签段

示例

stream {
        upstream ssh_proxy {
                hash $remote_addr consistent;                               #调度算法一致性hash
                server 192.168.19.201:22 max_fails=2 fail_timeout=10s;         #健康状态检测
                server 192.168.19.202:22 max_fails=2 fail_timeout=10s;
                }
        server {
                listen 2222;
                proxy_connect_timeout 1s;                       #连接后端服务器的超时时间
                proxy_timeout 10s;                              #连接超时时间,如果不配置,永远不超时
                proxy_pass ssh_proxy;
                }
}

猜你喜欢

转载自blog.csdn.net/weixin_43342753/article/details/89644119