Giter Club home page Giter Club logo

docker-nginx-elb-websocket's Introduction

Dreams of Websockets

At Stockflare, we use this docker container to enable Websocket connections through AWS Elastic Load Balancers.

The container uses confd for a one-time configuration of Nginx when the container starts, using environment variables. The Nginx configuration file is written to work in conjunction with an Elastic Load Balancer, itself using ProxyProtocol.

Usage

The container requires the presence of three environment variables. These variables will be used to configure Nginx when the container starts.

Note: The resulting configuration is checked for validity.

Env Purpose
LISTEN_ON Determines which port Nginx will listen on
DESTINATION_HOSTNAME The hostname to proxy traffic to. This should typically be the name of the linked docker container (explained below)
DESTINATION_PORT The port to proxy traffic to on the destination container

Brief Example

Lets say that we have the following container running on a host:

docker run -p 45490:45490 -n app -d my_websocket_application

To enable this container to proxy traffic to that application, we would run the following command:

docker run --link app:app \
           -p 45400:45400 \
           -e LISTEN_ON=45400 \
           -e DESTINATION_HOSTNAME=app \
           -e DESTINATION_PORT=45490 \
           -d stockflare/nginx-elb-websocket

This container would then start listening to traffic on port 45400, forwarding it to your application container on port 45490.

If you were running these containers on EC2 hosts that were part of a load balanced auto scaling group, the load balancer would be configured with the aforementioned ProxyProtocol on port 45400, complete with listeners forwarding TCP type traffic to port 45400.

The container also provides a naive health check for ELBs located at /ping.

Why is this needed?

Out-of-the-box, ELBs do not support Websockets and therefore require an additional proxy for which the connections must be negotiated through. There exist many blog posts on the internet, documenting the process for what we've done here. We wanted to create a more generic and complete approach to this. Below are some of the resources that we used:

docker-nginx-elb-websocket's People

Contributors

davidkelley avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.