nginx配置stream四层负载均衡(基于TCPIP)

本文介绍了如何确保Nginx版本不低于1.9.0并添加stream模块,强调了编译时必须包含--with-stream--with-stream_ssl_module。此外,详细展示了配置stream模块的步骤,包括日志格式、反向代理设置,以及如何平滑添加模块,实现不停机更新。
摘要由CSDN通过智能技术生成

1.nginx必须是1.9.0以上的版本,如果低于这个版本,需要额外打补丁,比较麻烦。

2.nginx(1.9.0以上的版本)编译的时候一定要带上 --with-stream --with-stream_ssl_module这两个模块,当然如果线上的nginx没有这两个模块,可以平滑添加模块,不用停机。

3.配置相关:

(1)nginx.conf

配置文件里,添加如下内容,stream配置跟http配置是对等的关系,所以要跟http分开。

stream {

            log_format proxy '$remote_addr [$time_local] '
                 '$protocol $status $bytes_sent $bytes_received '
                 '$session_time "$upstream_addr" '
                 '"$upstream_bytes_sent" "$upstream_bytes_received" "$upstream_connect_time"';

    access_log /var/log/nginx/tcp-access.log proxy ;
    open_log_file_cache off;
    include /usr/local/nginx/conf/conf.d/*.stream;
}

(2)具体的反向代理配置文件,这个其实跟http的配置方式一样。

upstream xxx_base{
        server 10.0.1.1:8890;
}
server {
        listen 8890;
        proxy_connect_timeout 5s;
        proxy_timeout 30s;
        proxy_pass xxx_base;
        access_log  /var/log/nginx/xxx_base_tcp.access.log  proxy;
        error_log /var/log/nginx/xxx_base_tcp.error.log;
    }

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值