反向代理udp
http://nginx.org/en/docs/stream/ngx_stream_core_module.html
- 注意:stream:server模塊中不支持tcp協(xié)議中的location配置二級目錄轉(zhuǎn)發(fā)
確定nginx版本及模塊【注意】
nginx -V
- 版本號需要>1.9.0
- 模塊有 --with-stream【注意檢查】
增加配置
因?yàn)閡dp與tcp是同級的兩種通信協(xié)議,所以與http模塊平齊文章來源:http://www.zghlxwxcb.cn/news/detail-720010.html
- nginx.conf文件內(nèi)容增加如下stream配置
# udp模塊,使用stream關(guān)鍵字,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轉(zhuǎn)發(fā)到ipv6
server {
listen 19135;
proxy_connect_timeout 10s;
proxy_timeout 30s;
proxy_pass [2607:fcd0:107:3cc::1]:19135;
}
}
# http 協(xié)議模塊 ....
udp :說明是代理udp協(xié)議
reuseport :處理多個(gè)包為同一個(gè)會話時(shí)使用,保持會話的作用文章來源地址http://www.zghlxwxcb.cn/news/detail-720010.html
測試
- 通過nc開啟源udp服務(wù)端
nc -l -u 192.168.1.33 5433
- 通過另一個(gè)ssh容器連接代理udp端口
nc -uvz 192.168.1.33 15433
# Connection to 192.168.1.33 15433 port [udp/*] succeeded!
問題1:如何通過nginx向udp后端服務(wù)傳遞客戶真實(shí)IP
到了這里,關(guān)于使用nginx作udp協(xié)議的反向代理的文章就介紹完了。如果您還想了解更多內(nèi)容,請?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!