【问题标题】:Route mqtt and websocket traffic through apache2通过 apache2 路由 mqtt 和 websocket 流量
【发布时间】:2020-04-21 12:27:02
【问题描述】:

我在 Ubuntu EC2 上设置了 emqx 代理。

当我尝试通过带有 IP 地址的 websocket 连接到 emqx 时,它工作正常。 但是当我使用子域时,连接失败。 我的 Apache 配置是

    <VirtualHost *:80>
  ServerName subdomain.example.com
  ServerAlias subdomain.example.com
  ServerAdmin admin@domain.in

  RewriteEngine On
  #RewriteCond %{REQUEST_URI}  ^/socket.io            [NC]
  #RewriteCond %{QUERY_STRING} transport=websocket    [NC]
  RewriteCond %{HTTP:Upgrade} =websocket [NC]
  RewriteRule ^/mqtt/(.*)           ws://localhost:8083/mqtt/$1 [P,L]

  ProxyPreserveHost On
  ProxyRequests Off

  ProxyPass / http://localhost:8083/
  ProxyPassReverse / http://localhost:8083/

  ErrorLog ${APACHE_LOG_DIR}/error.log
  CustomLog ${APACHE_LOG_DIR}/access.log combined

</VirtualHost>

Apache访问日志

我将 apache 的日志级别更改为“调试”,这些是错误日志。看起来它正在尝试查找 /mqtt 文件夹。

我已经启用了“proxy_wstunnel.load”模式。如何使用子域连接到 mqtt 和 ws?

【问题讨论】:

    标签: ssl websocket apache2 emq


    【解决方案1】:

    ServerName下添加ServerAlias指令

    例子:

    ServerName domain.com
    ServerAlias subdomain.domain.com
    
    Try adding this too
    
    ProxyPass "/" "http://127.0.0.1:8083/mqtt"
    ProxyPassReverse "/" "http://127.0.0.1:8083/mqtt"
    

    如果您不确定代理是否在使用 socket.io,请删除此行:

    #RewriteCond %{REQUEST_URI} ^/socket.io

    【讨论】:

    • 你必须重启服务器
    • 是的...我做到了。 sudo systemctl restart apache2
    • 我刚刚更新了 apache conf。你能再检查一下问题吗?
    • 我设置了日志级别来调试并添加了上面error.log文件的截图。你能再检查一下吗?
    • 处理传入连接的后端逻辑是什么?
    猜你喜欢
    • 2021-03-06
    • 1970-01-01
    • 1970-01-01
    • 2015-08-17
    • 2021-12-15
    • 2017-07-20
    • 1970-01-01
    • 1970-01-01
    • 2016-02-21
    相关资源
    最近更新 更多