ActiveMQ和NGINX

3

我可以理解...我们有一个使用NGINX代理隐藏的ActiveMQ需求,但我不知道如何设置。

对于ActiveMQ,我已为所有协议设置了不同的端口。

<transportConnectors>
        <!-- DOS protection, limit concurrent connections to 1000 and frame size to 100MB -->
        <transportConnector name="openwire" uri="tcp://0.0.0.0:62716?maximumConnections=1000&amp;wireFormat.maxFrameSize=104857600"/>
        <transportConnector name="amqp" uri="amqp://0.0.0.0:5782?maximumConnections=1000&amp;wireFormat.maxFrameSize=104857600"/>
        <transportConnector name="stomp" uri="stomp://0.0.0.0:62713?maximumConnections=1000&amp;wireFormat.maxFrameSize=104857600"/>
        <transportConnector name="mqtt" uri="mqtt://0.0.0.0:1993?maximumConnections=1000&amp;wireFormat.maxFrameSize=104857600"/>
        <transportConnector name="ws" uri="ws://0.0.0.0:62714?maximumConnections=1000&amp;wireFormat.maxFrameSize=104857600"/>
    </transportConnectors>

以下是类似这样的nginx配置:

server {
  listen *:61616;
  server_name           192.168.210.15;

  index  index.html index.htm index.php;

  access_log            /var/log/nginx/k1.access.log combined;
  error_log             /var/log/nginx/k1.error.log;

  location / {
    proxy_pass            http://localhost:62716;
    proxy_read_timeout    90;
    proxy_connect_timeout 90;
    proxy_redirect        off;
    proxy_method          stream;
    proxy_set_header      Host $host;
    proxy_set_header      X-Real-IP $remote_addr;
    proxy_set_header      X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header      Proxy "";
  }
}

(同样适用于其它 5 个重新定义的端口)

我以为这会暴露默认的 ActiveMQ 端口,并且 Nginx 会将其映射到新的定义,但实际上并不起作用。

我们正在使用 NodeJs 库 amqp10 的 3.1.4 版本进行通信。

而且所有端口在服务器上都是启用的......如果使用没有 nginx 代理的标准端口,则可以正常工作。

有人知道我漏掉了什么吗?感谢任何想法。

2个回答

2
您可以将ActiveMq隐藏在Nginx代理后面,即使您尝试为AMQP客户端代理OpenWire也是如此。
如果您将配置添加到http块中,则绑定将失败。
但是请注意,Nginx不仅支持http,还支持tcp块。
如果您通过tcp代理activemq,则在http级别发生的情况无关紧要,您仍然可以进行代理。
当然,您会失去与http一起使用时所具有的灵活性。
打开您的nginx.conf(位于/ etc / nginx / nginx.conf)。 这将有http块,其中又包含一些include语句。
在该http块之外,添加另一个include语句。
$ pwd
/etc/nginx
$ cat nginx.conf | tail -1
include /etc/nginx/tcpconf.d/*;

include语句指示nginx在目录“/etc/nginx/tcpconf.d/”中查找其他配置文件。 在此目录中添加所需的配置文件。 我们将其称为amq_stream.conf。

$ pwd
/etc/nginx/tcpconf.d
$ cat amq_stream.conf
stream {
    upstream amq_server {
        # activemq server
        server <amq-server-ip>:<port like 61616.;
    }

    server {
        listen 61616;
        proxy_pass amq_server;
    }
}

重新启动您的nginx服务。

$ sudo service nginx restart

你已经完成了


这是更好/正确的解决方案。谢谢@Manojkumar Khotele - Sean Malter
只是提一下,这个方法对我有效。 - Sean Malter

1

Nginx是一款能够代理WebSocket和HTTP的HTTP服务器。

但是,您正在尝试为AMQP客户端代理OpenWire。这与Nginx或Node.js不兼容。

因此,如果您确实需要使用Nginx,则需要将客户端协议更改为STOMP或MQTT over WebSocket。然后在Nginx中设置WebSocket代理。

Nginx示例带有TLS。更多细节请参见https://www.nginx.com/blog/websocket-nginx/

upstream websocket {
    server amqserver.example.com:62714;
}
server {
    listen 8883 ssl;
    ssl on;
    ssl_certificate /etc/nginx/ssl/certificate.cer;
    ssl_certificate_key /etc/nginx/ssl/key.key;

    location / {
        proxy_pass http://websocket;
        proxy_http_version 1.1;
        proxy_set_header Upgrade websocket;
        proxy_set_header Connection upgrade;
        proxy_read_timeout 120s;
    }
}

然而,由于您需要重写所有客户端代码,我会重新考虑Nginx的想法。还有其他软件和硬件可以作为TCP服务器的前端,并进行TLS终止等操作。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接