大网数据广告活动
服务器运维问答

haproxy acl with "header(host)" check is not working for mqtt backend

· 52CE 我爱测

I am trying to apply HAProxy acl to choose mqtt broker backend is not working. I have tried following HAProxy configurations. Environment: HAProxy version: 1.8.19 MQTT Broker: EMQ X Broker version 3.0 Sample Config 1 listen mqtt …

问题原文

原帖链接 · Shaukat Mahmood Ahmad · CC BY-SA 4.0

I am trying to apply HAProxy acl to choose mqtt broker backend is not working. I have tried following HAProxy configurations.

Environment:

HAProxy version: 1.8.19 MQTT Broker: EMQ X Broker version 3.0

Sample Config 1

listen mqtt
    bind *:80
    mode tcp
    maxconn 50000

    acl mqtt-request hdr_beg(host) -i mqtt.mydoamin.com
    use_backend backend_mqtt if mqtt-request

  backend backend_mqtt
    mode tcp
    server smg1 192.168.0.100:1883 check 

Sample Config 2

listen mqtt
    bind *:80
    mode tcp
    maxconn 50000

    acl mqtt_request req.payload(4,15) -m sub mqtt.mydoamin.com
    tcp-request content accept if mqtt_request
    use_backend backend_mqtt  if mqtt_request

  backend backend_mqtt
    mode tcp
    server smg1 192.168.0.100:1883 check

Sample Config 3

listen mqtt
    bind *:80
    mode tcp
    maxconn 50000

    acl host_mqtt hdr(host) -i mqtt.mydoamin.com
    use_backend backend_mqtt if host_mqtt

  backend backend_mqtt
    mode tcp
    server smg1 192.168.0.100:1883 check  

Sample Config 4

listen mqtt
    bind *:80
    mode tcp
    maxconn 50000

    use_backend backend_mqtt if { hdr_end(host) -i mqtt.mydoamin.com }

  backend backend_mqtt
    mode tcp
    server smg1 192.168.0.100:1883 check

None of above configurations is working to match the host (mqtt.mydoamin.com).

已采纳解答

原帖链接 · wurtel · CC BY-SA 4.0

If you're using mode tcp in haproxy then you can't match HTTP headers with hdr() etc.

Is HTTP being spoken on this connection? Then use mode http. If not (you're actually using MQTT protocol on port 80) then you cannot match the hostname, as that is not communicated over the connection. You can only use different MQTT brokers on one system by using differing IP addresses and/or different port numbers.

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2019-04-08)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 4.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。