How to enable WebSocket with nginx on an AWS Elastic Beanstalk server?

I am deploying a nodejs application on aws beanstalk servers and want to use the socket.io function based on the WebSocket protocol. I know there is a discussion here to connect directly to nodejs servers instead of using nginx as a proxy server. But if I still want to have nginx as a proxy server due to additional features provided by nginx, such as static files, ... etc.

I find that it already supports WebSocket proxying on nginx 1.3.13, and I found that it seems that the aws-elastic beanstalk still uses 1.2.x Nginx.

So, I am wondering if there is a way to update the nginx version under beanstalk and how to enable WebSocket proxying on the nodejs server.

thanks

+4
source share
2 answers

You will need an additional module that can be executed at the time of nginx compilation. To do this, you need to add the line below to your script configuration.

--add-module=/root/nginx_patched/nginx_tcp_proxy_module

Required if you want to enable sockets, for example for node.js socket.io. The full tutorial can be found here . Sorry for the link, but this is a pretty broad topic. You may need a walkthrough if you are starting from scratch.

Hope this helps.

0
source

( nginx)

1.Nginx config

location /ws/ 
{
  proxy_http_version 1.1;
  proxy_set_header Upgrade $http_upgrade;
  proxy_set_header Connection "upgrade";
  proxy_pass http://unix:/<<socket>>;
}
  1. TCP , .
0

All Articles