反向代理udp
http://nginx.org/en/docs/stream/ngx_stream_core_module.html
- 注意:stream:server模块中不支持tcp协议中的location配置二级目录转发
确定nginx版本及模块【注意】
nginx -V
- 版本号需要>1.9.0
- 模块有 --with-stream【注意检查】
增加配置
因为udp与tcp是同级的两种通信协议,所以与http模块平齐文章来源:https://www.toymoban.com/news/detail-720010.html
- nginx.conf文件内容增加如下stream配置
# udp模块,使用stream关键字,15433代理5433
stream {
upstream udptest {
server 192.168.1.33:5433;
}
upstream udptest2 {
server 192.168.1.33:5434;
}
server {
listen 15433 udp reuseport ;
proxy_connect_timeout 5s;
proxy_timeout 20s;
proxy_pass udptest;
}
server {
listen 25434 udp reuseport ;
proxy_connect_timeout 5s;
proxy_timeout 20s;
proxy_pass udptest2 ;
}
#ipv4转发到ipv6
server {
listen 19135;
proxy_connect_timeout 10s;
proxy_timeout 30s;
proxy_pass [2607:fcd0:107:3cc::1]:19135;
}
}
# http 协议模块 ....
udp :说明是代理udp协议
reuseport :处理多个包为同一个会话时使用,保持会话的作用文章来源地址https://www.toymoban.com/news/detail-720010.html
测试
- 通过nc开启源udp服务端
nc -l -u 192.168.1.33 5433
- 通过另一个ssh容器连接代理udp端口
nc -uvz 192.168.1.33 15433
# Connection to 192.168.1.33 15433 port [udp/*] succeeded!
问题1:如何通过nginx向udp后端服务传递客户真实IP
到了这里,关于使用nginx作udp协议的反向代理的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!