nginx udp代理聆听相同的端口并决定原始ip

发布于 2025-01-26 23:57:00 字数 346 浏览 1 评论 0 原文

我目前正在尝试根据原点进行NGINX代理工作,并将其传递给不同的IP。

stream {
    server {
        listen 1000 udp;
        proxy_pass 10.0.0.2;
        allow 10.0.0.3;
    }
    server {
        listen 1000 udp;
        proxy_pass 10.0.0.3;
        allow 10.0.0.2;
    }
}

显然,这是不起作用的,因为我无法在同一端口上两次听。我尝试了一些“如果”,但不允许那里。有什么想法吗?我只想代理两个IP之间的流量。

I am currently trying to make a nginx proxy work where it pass to different ips depending on the origin.

stream {
    server {
        listen 1000 udp;
        proxy_pass 10.0.0.2;
        allow 10.0.0.3;
    }
    server {
        listen 1000 udp;
        proxy_pass 10.0.0.3;
        allow 10.0.0.2;
    }
}

obviously this does not work as I can not listen on the same port twice. I tried something with "if" but it is not allowed there. Any ideas? I just want to proxy the traffic between the two ips.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

坏尐絯 2025-02-02 23:57:00

您需要透明的代理或某种数据包过滤器或防火墙,而不是 nginx ,因为它是反向代理,不适合您的任务。

You need transparent proxy or some kind of packet filter or firewall, not nginx, since it is reverse proxy and not suitable for your task.

時窥 2025-02-02 23:57:00

虽然我不确定您选择了解决任务的正确方法(除非您需要某种负载平衡),但是使用多个上游 blocks和 block:

stream {
    upstream first_upstream {
        server 10.0.0.2:1000;
    }
    upstream second_upstream {
        server 10.0.0.3:1000;
    }
    upstream third_upstream {
        server 10.0.0.4:1000;
    }
    geo $upstream_name {
        10.0.0.0/24  first_upstream;
        10.0.1.0/24  second_upstream;
        default      third_upstream;
    }
    server {
        listen 1000 udp;
        proxy_pass $upstream_name;
    }
}

“ http://nginx.org/en/docs/stream/ngx_stream_geo_module.html” rel =“ nofollow noreferrer”> geo

While I'm not sure you choose the right way to solve your task (unless you need some kind of load-balancing), however this this should be possible using several upstream blocks and the geo block:

stream {
    upstream first_upstream {
        server 10.0.0.2:1000;
    }
    upstream second_upstream {
        server 10.0.0.3:1000;
    }
    upstream third_upstream {
        server 10.0.0.4:1000;
    }
    geo $upstream_name {
        10.0.0.0/24  first_upstream;
        10.0.1.0/24  second_upstream;
        default      third_upstream;
    }
    server {
        listen 1000 udp;
        proxy_pass $upstream_name;
    }
}

If you need a load-balancing, see the TCP and UDP Load Balancing article.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文