问题描述
我使用 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? 配置了我的网络服务器。
- 配置的安全组 - 入站规则 TCP 8080
- 已配置的负载均衡器
- 为端口 8080 创建目标组 (TCP)
- 启用粘性(1 小时)
- 在 AWS Certificate Manager 中配置和创建 SSL
-
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 检查
我什至尝试打开所有端口(Inbond)的流量只是为了检查安全组,但仍然遇到相同的错误。
我怀疑问题在于配置负载均衡器、安全组和目标组?
有什么帮助或建议吗?
解决方法
我终于找到了解决方案。端口 8080 应该已添加到防火墙,我必须为端口 8080 创建一个新的目标组,然后我必须创建一个带有端口 http:8080 的负载均衡器并指向目标组。