Nginx的UDP转发配置
编译安装Nginx 从1.9.0开始,nginx就支持对TCP的转发,而到了1.9.13时,UDP转发也支持了。提供此功能的模块为ngx_stream_core。 不过Nginx默认没有开启此模块,所以需要手动安装 安装跳过 修改nginx.conf配置文件添加如下: TCP转发 stream { server { listen 3000; proxy_pass 127.0.0.1:3306; # 也支持socket # proxy_pass unix:/tmp/mysql.socket; } } UDP转发 目标: 发送UDP数据到3000端口,3001端口可以接收 stream { server { listen 3000 udp; proxy_pass 127.0.0.1:3001; } }
stream {
upstream mysql {
hash $remote_addr consistent;
server 192.168.1.41:6379 weight=5 max_fails=3 fail_timeout=30s;
server server unix:/tmp/mysql.sock
}
upstream dns {
server 192.168.0.1:53535;
server dns.example.com:53;
}
server {
listen 33061;
#listen 63795 so_keepalive=on;
#listen 63795 so_keepalive=30m::10;
proxy_connect_timeout 1s;
proxy_timeout 3s;
proxy_pass mysql;
}
server {
listen 127.0.0.1:53 udp reuseport;
proxy_timeout 20s;
proxy_pass dns;
}
server {
listen [::1]:12345;
proxy_pass unix:/tmp/stream.socket;
}
}
调整内核参数
# sysctl -p | grep tcp_keepalive
net.ipv4.tcp_keepalive_time = 300
net.ipv4.tcp_keepalive_probes = 5
net.ipv4.tcp_keepalive_intvl = 15
<< 上一篇
下一篇 >>
网友留言(0 条)