配置 Ratchet 和 EC2 以及 AWS 负载均衡器将 WebSocket 连接抛出到“wss://chat.domain.com:8080/”失败

问题描述

我使用 Ratchet 在 Ubuntu 20.04 (LAMP) 堆栈上构建了一个 Websocket。

我按照这篇文章 https://www.twilio.com/blog/create-php-websocket-server-build-real-time-even-driven-application 构建了 websocket。

我按照这篇文章 Does an Application Load Balancer support WebSockets? 配置了我的网络服务器。

  1. 配置的安全组 - 入站规则 TCP 8080
  2. 已配置的负载均衡器
  3. 为端口 8080 创建目标组 (TCP)

enter image description here

  1. 启用粘性(1 小时)
  2. 在 AWS Certificate Manager 中配置和创建 SSL

enter image description here

  1. Apache 配置

    <VirtualHost *:80>
        ServerName chat.domain.com
        ServerAdmin webmaster@localhost
        DocumentRoot /var/www/websites/chat.domain.com/public
           <Directory /var/www/websites/chat.domain.com/public/>
               Options Indexes FollowSymLinks MultiViews
               AllowOverride All
               Require all granted
           </Directory>
    
        ErrorLog ${APACHE_LOG_DIR}/chat.domain.com/error.log
        CustomLog ${APACHE_LOG_DIR}/chat.domain.com/access.log combined
    </VirtualHost>
    
    <VirtualHost *:443>
        ServerName chat.domain.com
        ServerAdmin webmaster@localhost
        DocumentRoot /var/www/websites/chat.domain.com/public
           <Directory /var/www/websites/chat.domain.com/public/>
                Options Indexes FollowSymLinks MultiViews
                AllowOverride All
                Require all granted
            </Directory>
    
        ProxyPass / https://chat.domain.com:8080/
        ProxyPassReverse / https://chat.domain.com:8080/
        <Location "/">
            ProxyPass "wss://chat.domain.com:8080/"
        </Location>
    
    
        ErrorLog ${APACHE_LOG_DIR}/chat.domain.com/error.log
        CustomLog ${APACHE_LOG_DIR}/chat.domain.com/access.log combined
    </VirtualHost>
    

一切都到位并运行,但我明白

WebSocket 连接到“wss://chat.domain.com:8080/”失败:

这是我的 chrome 检查

enter image description here

我什至尝试打开所有端口(Inbond)的流量只是为了检查安全组,但仍然遇到相同的错误

我怀疑问题在于配置负载均衡器、安全组和目标组?

有什么帮助或建议吗?

解决方法

我终于找到了解决方案。端口 8080 应该已添加到防火墙,我必须为端口 8080 创建一个新的目标组,然后我必须创建一个带有端口 http:8080 的负载均衡器并指向目标组。

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...