0

我在 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?

4

1 回答 1

0

在下添加ServerAlias指令ServerName

例子:

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

于 2020-04-21T12:31:35.057 回答