Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I customize nginx on AWS elastic beanstalk to loadbalance Meteor?

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 hereenter 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?

like image 343
aginsburg Avatar asked Nov 23 '14 00:11

aginsburg


People also ask

Where is nginx config Elastic Beanstalk?

The default nginx configuration Below is the default Elastic Beanstalk nginx configuration which is located at /etc/nginx/nginx. conf for most of the distributions. The location of this file will vary depending on how you installed the software on your machine.

Does Elastic Beanstalk use nginx?

Elastic Beanstalk uses nginx as the reverse proxy to map your application to your Elastic Load Balancing load balancer on port 80. Elastic Beanstalk provides a default nginx configuration that you can either extend or override completely with your own configuration.

Where is nginx config file in AWS?

By default this configuration is in the file /etc/nginx/conf.


1 Answers

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).

like image 127
aginsburg Avatar answered Oct 13 '22 18:10

aginsburg