Elastic Beanstalk 上的 WebSockets 与 Docker [英] WebSockets on Elastic Beanstalk with Docker

查看:26
本文介绍了Elastic Beanstalk 上的 WebSockets 与 Docker的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

暂时尝试在单个实例上运行的 AWS Elastic Beanstalk 中部署 Docker 映像.除了我通过 Socket.IO 使用的 WebSockets 之外,一切正常.

Trying to deploy a Docker image in AWS Elastic Beanstalk running on a single instance for now. It all works fine, apart from WebSockets which I am using through Socket.IO.

另一篇文章建议删除 nginx,但那要么不再可能,要么只是不适合使用 Docker 进行部署.

Another post suggests to remove nginx, but that is either not possible anymore or just not an option for deployments with Docker.

我有一个 python 脚本,可以更改 nginx 配置以允许 WebSocket 连接.当我通过 ssh 进入实例并运行该脚本时,它可以工作.但是,运行ebextensions时,nginx配置的那部分还不存在,所以我不能自动运行这个脚本.

I have a python script that changes the nginx configuration to allow WebSocket connections. When I ssh into the instance and run that script, it works. However, that part of the nginx configuration does not exist yet when ebextensions are run, so I cannot run this script automatically.

如果您想自己尝试,我正在尝试部署 databench_examples.当您使用 eb initeb start 部署它,然后通过 ssh 进入实例并转到 /var/app/current 和运行 sudo python nginx_socketio_conf.py 这会更改 nginx 配置文件.如果它不起作用,您会在运行 simplepi 分析时在浏览器控制台中看到 Socket.IO 握手的 500 错误.

If you want to try it yourself, I am trying to deploy databench_examples. It is working when you deploy this with eb init and eb start and then ssh into the instance and go to /var/app/current and run sudo python nginx_socketio_conf.py which changes the nginx configuration file. If it is not working, you see a 500 error in the browser console for the Socket.IO handshake when running the simplepi analysis.

推荐答案

运行 ebextensions 时 nginx 配置文件不存在是正确的.原因如下:该配置文件是在部署应用程序之后动态生成的,因为 Docker 容器的端口映射直到容器停止后才知道.因此,您由 ebextensions 执行的出色 Python 脚本没有可操作的配置文件.

You're correct that the nginx configuration file does not exist when ebextensions are run. Here's why: that config file is dynamically generated after the application is deployed because the port mapping for the Docker container isn't known until after the container stops. So your awesome Python script executed by ebextensions doesn't have a config file to operate on.

另一种常规方法不起作用,即将 nginx 配置文件写入/etc/nginx/conf.d 因为 location 指令必须存在于 serversites_enabled 配置中阻止.所以这是不行的.

Another conventional approach doesn't work, i.e., writing the nginx config file to /etc/nginx/conf.d because the location directive has to exist inside the server block in the sites_enabled config. So that's a no go.

我创建了一个 PR 来说明一种可行的方法:https://github.com/svenkreiss/databench_examples/pull/3 这是一种未公开的技术,可将 Python/nginx 突变脚本放入 Elastic Beanstalk 的 hooks 目录中的正确位置.然后,在生成 nginx 配置后,Elastic Beanstalk 会立即执行该脚本(Elastic Beanstalk 将按字母顺序在 hooks 子目录中运行可执行脚本,因此使用 01_ 前缀.

I created a PR to illustrate an approach that will work: https://github.com/svenkreiss/databench_examples/pull/3 This is an undocumented technique that drops the Python/nginx mutation script into the right place in Elastic Beanstalk's hooks directory. The script is then executed by Elastic Beanstalk immediately after the nginx configuration is generated (Elastic Beanstalk will run executable scripts in the hooks subdirectories in alphabetical order, hence the 01_ prefix.

谢谢,

埃文

这篇关于Elastic Beanstalk 上的 WebSockets 与 Docker的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆