请教 Nginx 端口范围监听和代理的问题

2020 年 10 月 22 日
 okr
需要将 本机 10000-20000 的 UDP 端口代理至 1.1.1.1 的 10000~20000 端口,目前已知的是 nginx 可以监听端口范围,但是代理到目标地址的端口段却还没找到方法,有知道的大佬吗?
5214 次点击
所在节点    NGINX
16 条回复
lazyfighter
2020 年 10 月 22 日
mark 比较好奇什么场景
momo1999
2020 年 10 月 22 日
写个小程序生成一下配置?
justseemore
2020 年 10 月 22 日
为啥不用 haproxy?
okr
2020 年 10 月 22 日
@lazyfighter 为了不暴露后面的服务器
@shuax 写 N 调代理规则吗?

配置:
```
upstream abc {
server 1.1.1.1:10000-20000; #这一步无法解决
}
server {
listen 10000-20000 udp;
proxy_connect_timeout 3s;
proxy_timeout 3s;
proxy_pass abc;
}
```
okr
2020 年 10 月 22 日
@zpfhbyx 需要代理 UDP 的
justseemore
2020 年 10 月 22 日
@ghtstice 啊.sorry ,审题不严
Cooky
2020 年 10 月 22 日
费那个劲你还不如直接 iptables
lvzhiqiang
2020 年 10 月 22 日
@Cooky 正解,DNAT 就可以了。
Xusually
2020 年 10 月 22 日
iptables 、ufw 、firewalld 退出了聊天
superrichman
2020 年 10 月 22 日
试试 upstream 不写端口 server 改成 proxy_pass abc:$server_port;
superrichman
2020 年 10 月 22 日
@superrichman 不过这需求是挺奇怪的,一般端口转发可不是 nginx 做的
okr
2020 年 10 月 22 日
@Cooky
@lvzhiqiang
@Xusually

因为其他端口还有负载的需求,所以采用了 nginx 。


@superrichman 这样试了下不行。因为其他端口还有负载的需求,所以采用了 nginx 。
okr
2020 年 10 月 22 日
@Cooky
@lvzhiqiang
@Xusually
@superrichman 再请教下,如果用 iptables 的话,回路上会有问题吗?因为媒体流
dorothyREN
2020 年 10 月 22 日
iptables 一条命令的事。。。。为啥搞这么麻烦
okr
2020 年 10 月 23 日
@dorothyREN 用 iptables 回路上会有问题吗?
UnknownSky
2021 年 1 月 5 日
nginx udp 轉發唯一的功能就是轉發 DNS :)

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/717434

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX