nginx做四层转发需要用到stream模块,编译时需要指定:–with-stream
–with-stream enable TCP/UDP proxy module
在nginx配置文件里面跟http同级的配置段:
stream {
upstream mysql_3306{
server 172.18.0.10:3306;
}
server {
listen 23306;
proxy_connect_timeout 5s;
proxy_timeout 300s;
proxy_pass mysql_3306;
}
}
TCP localhost:23306== > 172.18.0.10:3306