美文网首页
nginx stream模块

nginx stream模块

作者: 麟之趾a | 来源:发表于2021-07-18 17:06 被阅读0次

stream

nginx的stream模块是做四层的代理,但nginx是在应用层,可以简单理解为nginx在用户空间,监听一个端口,建立了一个管道,把来自客户端的请求,分发到服务端。也可以理解为是DNAT操作。不会改变请求内容,也不会做缓存。因为它是四层调度,根本不知道哪些东西需要缓存

简单用法

stream {
    server {
        listen 3306;
        proxy_pass 10.0.0.1:3306;
       }
}

如果后端服务器有多个,也可以使用upstream模块做负载,支持least_conn,least_time,hash,wlc,wrr等调度算法
https://nginx.org/en/docs/stream/ngx_stream_upstream_module.html

stream {
    upstream mysql_test {
      hash $remote_ip consisten;
      server 10.0.0.1:3306;
      server 10.0.0.2:3306;
    }
    server {
        listen 3306;
        proxy_pass mysql_test;
       }
}

相关文章

网友评论

      本文标题:nginx stream模块

      本文链接:https://www.haomeiwen.com/subject/edjapltx.html