› NGINX
› NGINX Trac
› 3rd Party Modules
› Security Advisories
› CHANGES
› OpenResty
› ngx_lua
› Tengine
在线学习资源
› NGINX 开发从入门到精通
NGINX Modules
› ngx_echo
okr
V2EX  ›  NGINX

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

  •  
  •   okr · Oct 22, 2020 · 5532 views
    This topic created in 2206 days ago, the information mentioned may be changed or developed.
    需要将 本机 10000-20000 的 UDP 端口代理至 1.1.1.1 的 10000~20000 端口,目前已知的是 nginx 可以监听端口范围,但是代理到目标地址的端口段却还没找到方法,有知道的大佬吗?
    16 replies  •  2021-01-05 13:33:22 +08:00
    lazyfighter
    lazyfighter
    Oct 22, 2020
    1
    mark 比较好奇什么场景
    momo1999
    momo1999
    Oct 22, 2020
    2
    写个小程序生成一下配置?
    justseemore
    justseemore
    Oct 22, 2020
    3
    为啥不用 haproxy?
    okr
    okr
    OP
    Oct 22, 2020
    4
    @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
    okr
    OP
    Oct 22, 2020
    5
    @zpfhbyx 需要代理 UDP 的
    justseemore
    justseemore
    Oct 22, 2020
    6
    @ghtstice 啊.sorry ,审题不严
    Cooky
    Cooky
    Oct 22, 2020 via Android❤️1
    7
    费那个劲你还不如直接 iptables
    lvzhiqiang
    lvzhiqiang
    Oct 22, 2020
    8
    @Cooky 正解,DNAT 就可以了。
    Xusually
    Xusually
    Oct 22, 2020
    9
    iptables 、ufw 、firewalld 退出了聊天
    superrichman
    superrichman
    Oct 22, 2020
    10
    试试 upstream 不写端口 server 改成 proxy_pass abc:$server_port;
    superrichman
    superrichman
    Oct 22, 2020 via iPhone
    11
    @superrichman 不过这需求是挺奇怪的,一般端口转发可不是 nginx 做的
    okr
    okr
    OP
    Oct 22, 2020
    12
    @Cooky
    @lvzhiqiang
    @Xusually

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


    @superrichman 这样试了下不行。因为其他端口还有负载的需求,所以采用了 nginx 。
    okr
    okr
    OP
    Oct 22, 2020
    13
    @Cooky
    @lvzhiqiang
    @Xusually
    @superrichman 再请教下,如果用 iptables 的话,回路上会有问题吗?因为媒体流
    dorothyREN
    dorothyREN
    Oct 22, 2020
    14
    iptables 一条命令的事。。。。为啥搞这么麻烦
    okr
    okr
    OP
    Oct 23, 2020
    15
    @dorothyREN 用 iptables 回路上会有问题吗?
    UnknownSky
    UnknownSky
    Jan 5, 2021 via Android
    16
    nginx udp 轉發唯一的功能就是轉發 DNS :)
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   2053 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 39ms · UTC 02:24 · PVG 10:24 · LAX 18:24 · JFK 21:24
    ♥ Do have faith in what you're doing.