nginx stream

 

4.修改配置文件

vim /opt/nginx/conf/nginx.conf(在配置文件最后行添加如下)
    stream {
      upstream NAME1 {
        hash $remote_addr consistent;
        server 10.22.0.7:5000 max_fails=3 fail_timeout=30s;
        server 10.22.0.8:5000 max_fails=3 fail_timeout=30s;
      }
      upstream NAME2 {
        hash $remote_addr consistent;
        server 192.168.5.8:8080 max_fails=3 fail_timeout=30s;
      }
      server{
      listen 8080;
        proxy_connect_timeout 1s;
        proxy_timeout 3s;
        proxy_pass NAME1;
      }
      server{
      listen 60000;
        proxy_connect_timeout 1s;
        proxy_timeout 3s;
        proxy_pass NAME2;
      }
    }
解析:

如上配置文件的含义为
将端口8080反向代理NAME1组的serverIP:PORT,最大失败次数为3,超时时间为30秒;
将端口60000反向代理NAME2组的serverIP:PORT,最大失败次数为3,超时时间为30秒。



作者:辉耀辉耀
链接:https://www.jianshu.com/p/5dcd1e027e17
来源:简书
著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。
posted @ 2020-03-29 21:31  agang_19  阅读(672)  评论(0编辑  收藏  举报