By - 12/29/2020
We've been working on some multiplayer capabilities for our classic card game site Solitaired, and have been exploring how to do this using Websockets.
Our stack is:
I Googled a bunch, but the articles I read (from 2017 and 2019 respectively) didn't quite work based on Amazon's latest updates.
So, consider this the 2020 edition of how to get Websockets to work on Elastic Beanstalk with Node.js.
Before starting, first make sure:
Then, make a file in the
.ebextensions directory in your application root. Call it
Then paste the contents below to that file.
This is correct:
files: "/etc/nginx/conf.d/websockets.conf": content: | proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection "upgrade";
Commit this file and deploy to Beanstalk. Voila.
Just for reference, here is the pre-2020 version of the file above.
Do not do it this way anymore:
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