意外的HTTP请求:POST/mqtt/auth

意外的HTTP请求:POST/mqtt/auth,mqtt,emq,Mqtt,Emq,我是emqtt的新手。我正在尝试使用emq_auth_http,但它不起作用 我有这3个请求来控制台一些数据,并将状态为200的数据发送回 app.post('/mqtt/auth', function(req, res) { console.log('This is body ', req.body); res.status(200).send(req.body); }); app.post('/mqtt/superuser', function(req, res) { console.log

我是emqtt的新手。我正在尝试使用emq_auth_http,但它不起作用

我有这3个请求来控制台一些数据,并将状态为200的数据发送回

app.post('/mqtt/auth', function(req, res) {
console.log('This is body ', req.body);
res.status(200).send(req.body);
});
app.post('/mqtt/superuser', function(req, res) {
console.log('This is body in superuser ', req.body);
res.status(200).send(req.body);
});
app.get('/mqtt/acl', function(req, res) {
console.log('This is params in acl ', req.params);
res.status(200).send(req.body);
});
邮递员的请求很有效

我已使用docker在windows上配置了emqtt。我已将配置文件放在/etc/plugins/emq_auth_http.conf中

这是我的配置文件

## Variables: %u = username, %c = clientid, %a = ipaddress, %P = password, %t = topic

auth.http.auth_req = http://127.0.0.1:3000/mqtt/auth
auth.http.auth_req.method = post
auth.http.auth_req.params = clientid=%c,username=%u,password=%P

auth.http.super_req = http://127.0.0.1:3000/mqtt/superuser
auth.http.super_req.method = post
auth.http.super_req.params = clientid=%c,username=%u

## 'access' parameter: sub = 1, pub = 2
auth.http.acl_req = http://127.0.0.1:3000/mqtt/acl
auth.http.acl_req.method = get
auth.http.acl_req.params = 
access=%A,username=%u,clientid=%c,ipaddr=%a,topic=%t
然后我从仪表板启用了emq_auth_http

现在,当我尝试将mqtt客户机连接到服务器时,它没有调用api。它记录

09:28:29.642 [error] Unexpected HTTP Request: POST /mqtt/auth
09:28:29.644 [error] Client(19645050-9d1b-4c50-acf9- 
c1fe7e69eea8@172.17.0.1:60968): Username 'username' login failed for 404
有什么我错过的吗?为什么它不起作用


谢谢,容器中的127.0.0.1指的是容器本身,而不是主机。您应该设置主机ip,您可以通过发出可以找到的命令
/sbin/ip route | awk'/default/{print$3}'
从容器获取主机ip

ps:这样你可以得到docker机器的ip而不是主机,如果你的服务是由windows提供的,你可以从10.0.75.1的容器中获得主机的ip。你可以在网上找到它

node.js代码在哪里运行?鉴于emq在docker中运行,您确定
127.0.0.1
指向您认为的位置吗?当被emq调用时,node.js代码是否记录了任何内容?node js代码正在我的本地主机上运行。我还通过在服务器上部署代码对其进行了测试。这就是问题所在nodejs代码DDoS不记录任何内容。我认为请求没有到达nodejs服务器解释为什么这是一个答案。在配置文件中,ip设置为127.0.0.1,但在一个容器中,这个ip指的是容器本身,配置文件中正确的ip地址必须是主机ip,在容器中使用上述命令将为主机提供ip,在大多数情况下,docker for windows的ip为10.0.75.1。请确保该服务允许从主机外部进行连接。就服务而言,docker容器是另一台机器。还要确保Windows防火墙允许与服务进行通信简单地说,使用网络中的内部IP,而不是本地主机。因为容器中的localhost与实际计算机上的localhost不同。