本文介绍了如何使用 AMQP 协议连接到 Nginx 反向代理后面的 RabbitMQ的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个用 C# 构建的客户端应用程序,它使用 AMQP 与 RabbitMQ 通信,但由于消息代理被移到 Nginx 反向代理后面,它停止工作.我如何配置 Nginx 以使用 AMQP,如果不可能,我有哪些替代方案?

I have a client application built with C# that communicates with RabbitMQ using AMQP but since the message broker was moved behind a Nginx reverse proxy it stopped working.How can i configure Nginx to work with AMQP and if is not possible which alternatives do i have?

推荐答案

Nginx 可以配置为负载平衡 TCP 和 UDP,因此您可以配置 nginx 进行 tcp 负载平衡,并以类似于代理 HTTP 的方式使用它.此处链接到文档:https://docs.nginx.com/nginx/admin-guide/load-balancer/tcp-udp-load-balancer/

Nginx can be configured to load balance TCP and UDP so you could configure nginx for tcp load balancing and use it in a similar way to if you were proxying HTTP. Link to documentation here: https://docs.nginx.com/nginx/admin-guide/load-balancer/tcp-udp-load-balancer/

示例配置:

stream {
    upstream stream_backend {
        least_conn;
        server backend1.example.com:12345 weight=5;
        server backend2.example.com:12345 max_fails=2 fail_timeout=30s;
        server backend3.example.com:12345 max_conns=3;
    }

    server {
        listen        12345;
        proxy_pass    stream_backend;
        proxy_timeout 3s;
        proxy_connect_timeout 1s;
    }

    server {
        listen     12346;
        proxy_pass backend4.example.com:12346;
    }
}

这篇关于如何使用 AMQP 协议连接到 Nginx 反向代理后面的 RabbitMQ的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-07 00:12