【发布时间】:2019-06-30 00:01:34
【问题描述】:
我已经阅读了几篇博客文章,并按照他们关于如何使用 Application Load Balancer (ALB) 让 Node Websockets 与 AWS Elastic Beanstalk (EB) 一起工作的说明进行操作 - 无济于事。
在本地使用时,应用程序可以与 Websockets 一起正常工作 (localhost)。
在EB中,App正常加载并在Browser中显示,但是Websocket没有连接,最终超时。
WebSocket connection to 'ws://tradey-12-hr-dev.ap-northeast-1.elasticbeanstalk.com:3030/' failed: Error in connection establishment: net::ERR_CONNECTION_TIMED_OUT
根据博客文章,我在.ebextensions/enable-websockets.config 的应用中添加了以下内容:
container_commands:
enable_websockets:
command: |
sed -i '/\s*proxy_set_header\s*Connection/c \
proxy_set_header Upgrade $http_upgrade;\
proxy_set_header Connection "upgrade";\
' /tmp/deployment/config/#etc#nginx#conf.d#00_elastic_beanstalk_proxy.conf
这是设置 websocket 的后端代码。在 BE 和 FE 中使用的端口是 3030。
import WebSocket from 'ws'
const setUpWebsocketServer = port => new WebSocket.Server({ port })
export default setUpWebsocketServer
这是启动握手的前端代码:
const target = window.location.host === 'localhost:3000' ?
'localhost' : window.location.host
const ws = new WebSocket(`ws://${target}:${PORT}`)
这是最后 100 行日志的链接。没有产生错误:
https://gist.github.com/bengrunfeld/e2f46e3575a3f57a68ed3c39fd63e7d8
我希望这是一件小事,我的直觉告诉我,我必须允许通过安全组或其他方式访问端口 3030 的流量 - 我什至在所有安全组上创建了新的入站流量规则,允许来自“ Anywhere',但这也不起作用(见附图)。
提前感谢您的帮助 =)
【问题讨论】:
标签: node.js amazon-web-services amazon-ec2 websocket amazon-elastic-beanstalk