Skip to content

Instantly share code, notes, and snippets.

@MitchPierias
Created March 18, 2019 14:33
Show Gist options
  • Save MitchPierias/526e7d94c59e59b844becef17cde9388 to your computer and use it in GitHub Desktop.
Save MitchPierias/526e7d94c59e59b844becef17cde9388 to your computer and use it in GitHub Desktop.
Nginx Reverse Proxy for Docker

Nginx reverse proxy for Docker

This was created to help expose ports for an ArangoDB container running on a Ubuntu EC2 instance

For this example, let's assume the container we want to expose is called arangodb-instance, our Nginx instance will be nginx, and our network will be called reverse-proxy. Start by creating our new network.

docker network create reverse-proxy

Next we need to connect our network to the exisitng container we would like to expose.

docker network connect reverse-proxy arangodb-instance

Start our Nginx server and link our network to create the interface for our reverse proxy. We're going to directly port the existing port 8529 through the Nginx port 8529, so no remapping ports, just apssing through.

docker run -d --name nginx --network reverse-proxy -p 8529:8529 nginx

You don't need to remove the default config file, but we are going to here.

docker exec nginx rm /etc/nginx/conf.d/default.conf

Now we can create a new config file called arango.conf with the following definition.

server {
    listen 8529;

    location / {
        proxy_pass http://arangodb-instance:8529;
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection 'upgrade';
        proxy_set_header Host $host;
        proxy_cache_bypass $http_upgrade;
    }
}

Notice we listen on port 8529 and pass those requests through to the arangodb-instance listening through http on port 8529.

Finally we can add/update the Nginx config file into our nginx container and update.

docker cp ./arango.conf nginx:/etc/nginx/conf.d/arango.conf
docker restart nginx
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment