且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何使用 AMQP 协议连接到 Nginx 反向代理后面的 RabbitMQ

更新时间:2022-04-18 01:53:09

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;
    }
}