A simple reverse proxy system built in Go, designed to route HTTP requests to backend services based on path prefixes. Includes two sample backend servers (server_a and server_b) and a proxy service, all containerized for easy setup using Docker Compose.
- Reverse proxy: Routes traffic to backend services based on path.
- Health checks: Each backend service exposes a
/healthendpoint, used by the proxy to determine availability. - Dockerized: All services provided with Dockerfiles and ready for multi-service orchestration using
docker-compose. - Configurable: Proxy configuration via a simple JSON file.
own-reverse-proxy/
├── docker-compose.yml
├── reverse_proxy/
│ ├── Dockerfile
│ ├── config.json
│ └── main.go
├── server_a/
│ ├── Dockerfile
│ └── main.go
├── server_b/
│ ├── Dockerfile
│ └── main.go
└── ...
git clone https://github.com/george124816/own-reverse-proxy.git
cd own-reverse-proxyThe reverse proxy reads its configuration from reverse_proxy/config.json:
{
"/joao": {
"target": "joao",
"port": 4300
},
"/george": {
"target": "george",
"port": 4200
}
}You can edit this file to add or change routes.
You can use the reverse proxy to route traffic to any service, for example an Nginx container. Here’s a simple example:
Create a file named health in your project directory with the following content:
ok
This file will be served by Nginx as a static health check endpoint.
services:
crazy_service:
image: nginx:latest
volumes:
- ./health:/usr/share/nginx/html/health:ro
own_reverse_proxy:
image: george124816/own-reverse-proxy:f754ab910f90a7bcb6bf0aac7fe090c2bbc73d43
volumes:
- ./config.json:/bin/config.jsoncrazy service: Runs Nginx and serves a static/healthfile with the contentok.own reverse proxy: Runs the reverse proxy using a published image and your config file.
Make sure your config file points to the Nginx service and port (default for Nginx is 80):
{
"/crazy": {
"target": "crazy_service",
"port": 80
}
}docker compose up --build-
Health check (proxied):
curl http://localhost/crazy/health # Output: ok -
Any other proxied endpoint (for example, serving Nginx root):
curl http://localhost/crazy/ # Output: nginx welcome page HTML
- The reverse proxy listens on port 80 and forwards requests to backend services according to the path.
- Health checks are performed every second; if a backend is unhealthy, requests to its route will receive a 503 error.
docker compose downTo add more backend services:
- Create a folder (e.g.,
server_c) with a Dockerfile and Go service, or use a prebuilt image. - Add it to
docker-compose.yml. - Update
reverse_proxy/config.jsonto add a new route.
- If you see
Health Check failedorService unavailable, check that the backend containers are running and healthy. - For advanced logs, check each container's output.
Contributions are welcome! Feel free to open issues or submit pull requests.
MIT (or your chosen license).