3

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?

1 Answer 1

4

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.

Sign up to request clarification or add additional context in comments.

4 Comments

That works but I would recommend using ebextensions and setting an option setting to set the protocol to tcp. That way if you rebuild your environment or clone your environment the settings on your load balancer will persist. You can do this by creating a file .ebextensions/load_balancer.config in your app with the option setting "namespace: aws:elb:loadbalancer" and "option_name: LoadBalancerProtocol" and "value: TCP". If you deploy this app source to your environment the settings will persist across rebuilds, clone and saved configurations.
The list of supported option settings is available here: docs.aws.amazon.com/elasticbeanstalk/latest/dg/… Here is an example of how to setting option settings in an ebextensions config file docs.aws.amazon.com/elasticbeanstalk/latest/dg/… The file is in yaml format
I certainly agree it's better to have it work from a cli. I don't know about your .ebextensions approach as I've always managed to avoid it. Instead I'm passing in the LoadBalancerPortProtocol you suggest (though maybe you've got a typo?) by using aws elasticbeanstalk create-environment and passing it in using --option-settings.
I see ... option settings can be set either via the API/CLI/ebextensions. They are all equivalent. When I read your answer at first I misunderstood that you modified the properties directly on the load balancer but since you modified the load balancer settings via the beanstalk console the console sets the option settings via the API which is the similar to setting it via ebextensions. Essentially the state is preserved in your environment configuration when you do it via beanstalk console, api, cli or ebextensions.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.