nginx 四层转发配置

tcp转发  

Nginx 需要支持--with-stream

  • 四层代理依赖模块ngxstreamcore_module,该模块自1.9.0版开始可用。默认情况下,此模块不构建,应使用配置参数启用 --with-stream
nginx version: nginx/1.17.9  
built by gcc 4.8.5 20150623 (Red Hat 4.8.5-36) (GCC)  
built with OpenSSL 1.0.2k-fips  26 Jan 2017  
TLS SNI support enabled  
configure arguments: --prefix=/data/soft/nginx --with-http_ssl_module --with-http_stub_status_module --with-http_realip_module --with-http_sub_module --with-pcre --with-stream --with-threads --with-http_v2_module

TCP localhost:23306== > 192.168.1.10:3306

stream {  
    upstream mysql_3306{
        server 192.168.1.10:3306;
    }
    server {
        listen 23306;
        proxy_connect_timeout 5s;
        proxy_timeout 300s;
        proxy_pass mysql_3306;
    }