我是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。It日志
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有什么我漏掉的吗?为什么它不工作?
谢谢
发布于 2019-02-20 15:39:07
容器中的127.0.0.1指的是容器本身,而不是主机。您应该设置主机ip,您可以通过发出命令/sbin/ip route|awk '/default/ { print $3 }'从容器中获取主机ip,该命令可以在here中找到
ps:这样你可以得到docker机器的ip,而不是主机的ip,如果你的服务是windows服务的,你可以从容器中到达主机的ip,即10.0.75.1。您可以在How to connect to docker host from container on Windows 10 (Docker for Windows)中找到它
https://stackoverflow.com/questions/51856371
复制相似问题