thund
thund

Reputation: 1953

Websockets on ElasticBeanstalk giving 404

I'm trying to deploy a websocket server to Elastic Beanstalk. I have a Docker container that contains both nginx and a jar server, with nginx just doing forwarding. The nginx.conf is like this:

listen 80;
location /ws/ {             # <-- this part only works locally
    proxy_pass http://127.0.0.1:8090/;     # jar handles websockets on port 8090
    proxy_http_version 1.1;
    proxy_set_header Upgrade $http_upgrade;
    proxy_set_header Connection "upgrade";
}
location / {                     # <-- this part works locally and on ElasticBeanstalk
    proxy_pass http://127.0.0.1:8080/;   # jar handles http requests on port 8080
    proxy_set_header   Host $host;
    proxy_set_header   X-Real-IP $remote_addr;
    proxy_set_header   X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header   X-Forwarded-Host $server_name;
}

I can run this docker locally and everything works fine - http requests are served, and I can connect websockets using ws://localhost:80/ws/ However, when I deploy to Elastic Beanstalk, http requests are still ok, but trying to connect websockets on ws://myjunk.elasticbeanstalk.com:80/ws/ gives a 404 error. Do I need something else to allow websockets on Elastic Beanstalk?

Upvotes: 3

Views: 1547

Answers (1)

thund
thund

Reputation: 1953

Ok, got it working. I needed the ElasticBeanstalk load balancer to use TCP instead of HTTP.

To do this from the AWS console (as it's laid out on 5/16/2015), go to your ElasticBeanstalk environment, choose "Configuration" on the left menu, under "Network Tier" there's a "Load Balancing" pane. Click its cog wheel, then you can change the load balancer protocol from http to tcp.

Upvotes: 4

Related Questions