/nginx-loadbalancer-go-api

An extremely simple demo for using NGINX as a reverse proxy/load balancer serving a Go-based API...with GitHub Actions CI/CD

Primary LanguageGo

Using NGINX as a load balancer for a Go-based API in Docker containers

h/t to @zerefwayne for the idea🔥🔥🔥!


PURPOSE

This repo demonstrates how to use NGINX as a reverse proxy/load balancer serving a web application based on an API written in Go, and running in Docker containers 🔀.

(It also demos how to use GitHub Actions for scalable CI/CD) 📈.


DOCUMENTATION

You can find the full explanation for the original repo on codeburst.


USAGE

Spin-up the containers hosting the API server - there are 5 by default, but can be scaled up/down:

  • docker-compose up -d --build

...then make an HTTP request against the load balancer:

  • curl -X GET localhost/hi

DOCKER HUB IMAGE

You can spin-up a pre-built image on Docker Hub by pulling the image to your server:

  • docker pull jasonsalas/nginx-loadbalancer-go-api:latest

...or, you can also run this load balancer application on your server as a pre-built disk image by running the following commands in a terminal:

  • docker-compose -f docker-compose-for-docker-hub.yml up -d

Then, you'll need to verify which randomized port the API server your server is listening on (it'll be bound to port 5000 on the image):

  • docker-compose ps -a

For example, let's assume the port is 12345. Use this port to make a HTTP request to the load balancer's endpoint:

curl -X GET localhost:12345/hi