nginx实现openfire负载均衡

Nginx版本必须是1.9以上,不然不支持tcp连接,要么加入其他插件

在nginx.conf文件中加入下图中的代码,图中的ip与端口配成自己的,配置好后,客户端请求listen监听的端口,ip为nginx所在服务器的地址,openfire服务器名称在集群中是一样的。例如我测试配置的:

Nginx所在服务地址:http://192.168.1.248

Listen监听端口:6222

Openfire服务器名称:test

stream {       

      upstream openfire5222 {                       

                hash $remote_addr consistent;                               

                server 192.168.1.249:5222 weight=5;                                                       

                server 192.168.1.248:5222 weight=5;             

        }       

        server {                       

            listen 6222;                               

            proxy_connect_timeout 10s; #设置连接超时时长  必须                         

            proxy_timeout 30s;  #设置代理超时时长          必须                   

            proxy_pass openfire5222;               

        }

}

原文地址:https://www.cnblogs.com/shihaiming/p/5924536.html