无限星辰工作室-客户无限互联网动力之源

标题: nginx反代理netty的Tcp/Udp端口例子 [打印本页]

作者: crx349    时间: 2020-10-20 23:34
标题: nginx反代理netty的Tcp/Udp端口例子
反代理netty时需要用到ngx_stream_core_module这个模块,nginx1.9以上自带,需要重新编译加上
  1. –with-stream
复制代码

例子:
注意:以下代码放http节点外
负载均衡版
  1. stream{
  2.          upstream socket_proxy {
  3.                  hash $remote_addr consistent;
  4.            server 127.0.0.1:6688 weight=5 max_fails=3 fail_timeout=30s;
  5.    
  6.            server 127.0.0.1:7777 weight=5 max_fails=3 fail_timeout=30s; #多机情况下就是负载均衡
  7.         }
  8.       
  9.       server {
  10.            
  11.             listen 8899;
  12.                         proxy_connect_timeout 5s;
  13.        proxy_timeout 5s;
  14.             proxy_pass socket_proxy ;



  15.           }  
  16.       }
复制代码

普通版:
  1. stream{
  2.          upstream socket_proxy {
  3.                 # hash $remote_addr consistent;
  4.            server 127.0.0.1:6688;
  5.    
  6.          
  7.         }
  8.       
  9.       server {
  10.            
  11.             listen 8899;
  12.                         proxy_connect_timeout 20s;
  13.        proxy_timeout 20s;
  14.             proxy_pass socket_proxy ;



  15.           }  
  16.       }
复制代码


说明:客户端访问8899端口时,转发给6688端口,测试工具SocketTool4




欢迎光临 无限星辰工作室-客户无限互联网动力之源 (https://www.xmspace.net/) Powered by Discuz! X3.4