我如何在nginx中配置MQTT

时间:2018-04-18 12:34:04

标签: nginx mqtt nginx-reverse-proxy

我需要在nginx中配置MQTT,我尝试使用以下代码

我在/usr/local/etc/nginx/mqtt.conf中添加了一个.conf文件

和mqtt.conf包含: -

log_format mqtt '$remote_addr [$time_local] $protocol $status 
$bytes_received ' 
            '$bytes_sent $upstream_addr';
upstream hive_mq {
server 127.0.0.1:18831; #node1
server 127.0.0.1:18832; #node2
server 127.0.0.1:18833; #node3
zone tcp_mem 64k;
}
match mqtt_conn {
    # Send CONNECT packet with client ID "nginx health check"
    send   
 \x10\x20\x00\x06\x4d\x51\x49\x73\x64\x70\x03\x02\x00\x3c\x00\x12
 \x6e\x67\x69\x6e\x78\x20\x68\x65\x61\x6c\x74\x68\x20\x63\x68\x65
 \x63\x6b;
    expect \x20\x02\x00\x00; # Entire payload of CONNACK packet
 }
server {
    listen 1883;
    server_name localhost;
    proxy_pass hive_mq;
    proxy_connect_timeout 1s;
    health_check match=mqtt_conn;
    access_log /var/log/nginx/mqtt_access.log mqtt;
    error_log  /var/log/nginx/in.log; # Health check notifications
    #access_log /var/log/nginx/access.log;
    #error_log  /var/log/nginx/error.log; # Health check notifications
}

我还在nginx.conf中添加了几个代码: -

worker_processes  1;
events {
worker_connections  1024;
}

 stream {
    include stream_conf.d/*.conf;
  }

我试图从mosquitto发布消息,如:

  mosquitto_pub -d -h localhost -p 1883 -t "topic/test" -m "test123" -i 
  "thing001"

但是我无法与nginx连接,任何帮助我如何配置它。

提前致谢:)

0 个答案:

没有答案