## Custom Nginx container for a Node ### Need * Since, BigchainDB and MongoDB both need to expose ports to the outside world (inter and intra cluster), we need to have a basic DDoS mitigation strategy to ensure that we can provide proper uptime and security these core services. * We can have a proxy like nginx/haproxy in every node that listens to global connections and applies cluster level entry policy. ### Implementation * For MongoDB cluster communication, we will use nginx with an environment variable specifying a ":" separated list of IPs in the whitelist. This list contains the IPs of exising instances in the MongoDB replica set so as to allow connections from the whitelist and avoid a DDoS. * For BigchainDB connections, nginx needs to have rules to throttle connections that are using resources over a threshold. ### Step 1: Build the Latest Container Run `docker build -t bigchaindb/nginx: .` from this folder. Optional: Upload container to Docker Hub: `docker push bigchaindb/nginx:` ### Step 2: Run the Container Note that the whilelist IPs must be specified with the subnet in the CIDR format, eg: `1.2.3.4/16` ``` docker run \ --env "MONGODB_FRONTEND_PORT=" \ --env "MONGODB_BACKEND_HOST=" \ --env "MONGODB_BACKEND_PORT=" \ --env "BIGCHAINDB_FRONTEND_PORT=" \ --env "BIGCHAINDB_BACKEND_HOST=" \ --env "BIGCHAINDB_BACKEND_PORT=" \ --env "BIGCHAINDB_WS_BACKEND_PORT=" \ --env "BIGCHAINDB_WS_FRONTEND_PORT=" \ --env "MONGODB_WHITELIST=" \ --env "DNS_SERVER=" \ --name=ngx \ --publish=: \ --publish=: \ --rm=true \ bigchaindb/nginx ``` For example: ``` docker run \ --env "MONGODB_FRONTEND_PORT=17017" \ --env "MONGODB_BACKEND_HOST=localhost" \ --env "MONGODB_BACKEND_PORT=27017" \ --env "BIGCHAINDB_FRONTEND_PORT=80" \ --env "BIGCHAINDB_BACKEND_HOST=localhost" \ --env "BIGCHAINDB_BACKEND_PORT=9984" \ --env="BIGCHAINDB_WS_FRONTEND_PORT=81" \ --env="BIGCHAINDB_WS_BACKEND_PORT=9985" \ --env "MONGODB_WHITELIST=192.168.0.0/16:10.0.2.0/24" \ --name=ngx \ --publish=80:80 \ --publish=17017:17017 \ --rm=true \ bigchaindb/nginx ``` ### Note: You can test the WebSocket server by using [wsc](https://slack-redir.net/link?url=https%3A%2F%2Fwww.npmjs.com%2Fpackage%2Fwsc) tool with a command like: `wsc -er ws://localhost:9985/api/v1/streams/valid_tx`.