V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
NGINX
NGINX Trac
3rd Party Modules
Security Advisories
CHANGES
OpenResty
ngx_lua
Tengine
在线学习资源
NGINX 开发从入门到精通
NGINX Modules
ngx_echo
ghtstice
V2EX  ›  NGINX

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

  •  
  •   ghtstice · 2020-10-22 14:00:39 +08:00 · 4237 次点击
    这是一个创建于 1253 天前的主题,其中的信息可能已经有所发展或是发生改变。
    需要将 本机 10000-20000 的 UDP 端口代理至 1.1.1.1 的 10000~20000 端口,目前已知的是 nginx 可以监听端口范围,但是代理到目标地址的端口段却还没找到方法,有知道的大佬吗?
    16 条回复    2021-01-05 13:33:22 +08:00
    lazyfighter
        1
    lazyfighter  
       2020-10-22 14:05:30 +08:00
    mark 比较好奇什么场景
    shuax
        2
    shuax  
       2020-10-22 14:08:12 +08:00
    写个小程序生成一下配置?
    zpfhbyx
        3
    zpfhbyx  
       2020-10-22 14:15:19 +08:00
    为啥不用 haproxy?
    ghtstice
        4
    ghtstice  
    OP
       2020-10-22 14:15:47 +08:00
    @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;
    }
    ```
    ghtstice
        5
    ghtstice  
    OP
       2020-10-22 14:17:10 +08:00
    @zpfhbyx 需要代理 UDP 的
    zpfhbyx
        6
    zpfhbyx  
       2020-10-22 14:18:41 +08:00
    @ghtstice 啊.sorry ,审题不严
    Cooky
        7
    Cooky  
       2020-10-22 14:20:38 +08:00 via Android   ❤️ 1
    费那个劲你还不如直接 iptables
    lvzhiqiang
        8
    lvzhiqiang  
       2020-10-22 14:56:46 +08:00
    @Cooky 正解,DNAT 就可以了。
    Xusually
        9
    Xusually  
       2020-10-22 15:03:10 +08:00
    iptables 、ufw 、firewalld 退出了聊天
    superrichman
        10
    superrichman  
       2020-10-22 15:09:41 +08:00
    试试 upstream 不写端口 server 改成 proxy_pass abc:$server_port;
    superrichman
        11
    superrichman  
       2020-10-22 15:11:20 +08:00 via iPhone
    @superrichman 不过这需求是挺奇怪的,一般端口转发可不是 nginx 做的
    ghtstice
        12
    ghtstice  
    OP
       2020-10-22 15:21:34 +08:00
    @Cooky
    @lvzhiqiang
    @Xusually

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


    @superrichman 这样试了下不行。因为其他端口还有负载的需求,所以采用了 nginx 。
    ghtstice
        13
    ghtstice  
    OP
       2020-10-22 16:39:03 +08:00
    @Cooky
    @lvzhiqiang
    @Xusually
    @superrichman 再请教下,如果用 iptables 的话,回路上会有问题吗?因为媒体流
    dorothyREN
        14
    dorothyREN  
       2020-10-22 18:34:45 +08:00
    iptables 一条命令的事。。。。为啥搞这么麻烦
    ghtstice
        15
    ghtstice  
    OP
       2020-10-23 10:10:30 +08:00
    @dorothyREN 用 iptables 回路上会有问题吗?
    UnknownSky
        16
    UnknownSky  
       2021-01-05 13:33:22 +08:00 via Android
    nginx udp 轉發唯一的功能就是轉發 DNS :)
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   3129 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 28ms · UTC 12:58 · PVG 20:58 · LAX 05:58 · JFK 08:58
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.