16

I am running Meteor on AWS Elastic Beanstalk. Everything is up and running except that it's not running Websockets with the following error:

WebSocket connection to 'ws://MYDOMAIN/sockjs/834/sxx0k7vn/websocket' failed: Error during WebSocket     handshake: Unexpected response code: 400 

My unstanding was to add something like:

proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection "upgrade";

To the proxy config, via my YML config file.

Via my .exbextension config file:

files:
"/etc/nginx/conf.d/proxy.conf" :
    mode: "000755"
    owner: root
    group: root
    content: |
        proxy_set_header        Upgrade         $http_upgrade;
        proxy_set_header        Connection      "upgrade";

I have ssh'd into the server and I can see the proxy.conf with those two lines in it.

When I hit my webserver I still see the "Error during WebSocket handshake: " error.

I have my beanstalk load configured with stick sessions and the following ports:

enter image description here enter image description here

BTW I did see https://meteorhacks.com/load-balancing-your-meteor-app.html and I tried to:

Enable HTTP load balancing with Sticky Session on Port 80 Enable TCP load balancing on Port 8080, which allows websocket But could not seem to get that working either.

Adding another shot at some YAML that does NOT work here": https://gist.github.com/adamgins/0c0258d6e1b8203fd051

Any help appreciated?

aginsburg
  • 1,223
  • 1
  • 12
  • 22

3 Answers3

16

With a LOT of help from AWS paid support, I got this working. The reality is I was not far off it was down to some SED syntaxt.

Here's what currently works (Gist):

option_settings:

  - option_name: AWS_SECRET_KEY
    value: <SOMESECRET>

  - option_name: AWS_ACCESS_KEY_ID
    value: <SOMEKEY>

  - option_name: PORT
    value: 8081

  - option_name: ROOT_URL
    value: <SOMEURL>

  - option_name: MONGO_URL
    value: <SOMEMONGOURL>

    - option_name: MONGO_OPLOG_URL
    value: <SOMEMONGOURL>

  - namespace: aws:elasticbeanstalk:container:nodejs
    option_name: ProxyServer
    value: nginx

    option_name: GzipCompression
    value: true

  - namespace: aws:elasticbeanstalk:container:nodejs:staticfiles

    option_name: /public
    value: /public

    container_commands:

  01_nginx_static:
    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

In addition to this you need to got into your Load balancer and change the Listener from HTTP to TCP:

enter image description here

described here: http://docs.aws.amazon.com/elasticbeanstalk/latest/dg/using-features.managing.elb.html).

George Stocker
  • 57,289
  • 29
  • 176
  • 237
aginsburg
  • 1,223
  • 1
  • 12
  • 22
  • Note I do have one open issue. I had to disable sticky sessions when swapping the protocol to TCP. I have an open question to understand if I get this back on. – aginsburg Dec 05 '14 at 04:30
  • OK, the discussion of how important websockets is here: https://groups.google.com/forum/#!topic/meteor-talk/M6L_Ihpu-e0 if you have any input please jump in – aginsburg Dec 08 '14 at 21:57
  • I currently have a dev/staging instance in ebs with no load balancer configured (scaling option is set to "single instance"). I presume this means I don't need to bother with that step? – gb96 Dec 18 '14 at 07:40
  • 1
    yep - the qyestion comes when you want to scale. It looks like opsworks or custom EC2 are only valid options right now... I am still working on it. It looks like I will need to build a custom proxy layer with either NGINX or HAPROXY as the out of the box HAPROXY on Opswork wont do it either... ahhh I can't wait to get this sorted out ... or until AWS starts supporting this out of the box on Beanstalk (hint ;-) ) – aginsburg Dec 22 '14 at 06:21
  • 1
    I ended up moving to use opsworks, cluster and docker as per https://blog.sunsama.com/meteor-docker-opsworks/ – aginsburg Jun 20 '15 at 20:25
  • 1
    I've just upvoted for just sharing your 'paid' help tricks with us. – scaryguy Nov 12 '15 at 08:10
0

Have you checked out Meteor WebSocket handshake error 400 with nginx? I think their configuration might be a bit different from yours. I'm in the same boat as you, trying to get this exact same set up working.

Community
  • 1
  • 1
  • Thanks for the response. Yep, I had seen this but this is a straight EC2 (not Beanstalk) example. I know what has to happen to the config file to make it work... I just can't seem to get the YAML Config right to get it to take. I am thinking I may need to use SED instead to try and update the existing NGINX config files vs append/add to them. So I think I am asking more about syntax vs what actually needs to be done. – aginsburg Dec 01 '14 at 01:10
  • I opened a paid support call with AWS yesterday... so will see what comes back. – aginsburg Dec 02 '14 at 21:21
0

This no longer works. I posted more here https://solitaired.com/websockets-elastic-beanstalk but the jist is create a file in .ebextensions (called websockets.config for example) with the following:

files:
  "/etc/nginx/conf.d/websockets.conf":
    content: |

      proxy_set_header Upgrade $http_upgrade;
      proxy_set_header Connection "upgrade";
  • I have just deployed a beanstalk and the websockets work fine without the config file. Is it still needed? (The deploy fails when I try adding this config file.) – httpete Feb 09 '21 at 06:46