https://github.com/okelet/front-back-gateway
Easyly configurable nginx proxy with backend and frontend endpoints
https://github.com/okelet/front-back-gateway
backend docker docker-compose frontend nginx proxy
Last synced: 2 months ago
JSON representation
Easyly configurable nginx proxy with backend and frontend endpoints
- Host: GitHub
- URL: https://github.com/okelet/front-back-gateway
- Owner: okelet
- Created: 2021-07-16T15:44:40.000Z (almost 5 years ago)
- Default Branch: main
- Last Pushed: 2021-08-20T14:04:19.000Z (almost 5 years ago)
- Last Synced: 2025-10-13T11:58:32.085Z (8 months ago)
- Topics: backend, docker, docker-compose, frontend, nginx, proxy
- Language: Shell
- Homepage:
- Size: 27.3 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Frontend/Backend gateway
[](https://github.com/okelet/front-back-gateway)
[](https://hub.docker.com/repository/docker/okelet/front-back-gateway)
This Docker image is based on the [nginx](https://hub.docker.com/_/nginx) image, and configures automatically a gateway, that forwards requests to two backends, simulating the frontend/backend pattern. This image was created to simulate the behaviour of the [Spring Cloud Gateway](https://spring.io/projects/spring-cloud-gateway) image, for doing the initial infrastructure deployment, before the real software is deployed. I usually use the [mendhak/http-https-echo](https://hub.docker.com/r/mendhak/http-https-echo) or [containous/whoami](https://hub.docker.com/r/containous/whoami) images as the backend.
You can test it using this command:
```bash
docker run --rm -it \
-p 8080:8080 -p 8443:8443 \
-e FRONTEND_URL=https://httpbin.org/anything/frontend \
-e BACKEND_URL=https://httpbin.org/anything/backend \
okelet/front-back-gateway:1.0
```
Nginx will forward the requests according to this configuration:
* `/api/*` -> backend
* `/*` -> frontend
For example:
* -> would return a JSON document, where the "url" field is
* -> would return a JSON document, where the "url" field is
You don't have to worry about invalid SSL certificates in the backends, as nginx, by default, doesn't check its validity when proxying the requests.
nginx is [configured to listen in the ports HTTP/8080 and HTTPS/8443](templates/nginx.conf.template) using a self signed certificate, valid for 10 years.
## Environment variables
* `BACKEND_URL` (mandatory): URL where requests under `/api` will be forwarded.
* `FRONTEND_URL` (mandatory): URL where requests not matching the previous route will be forwarded.
* `DNS_RESOLVER` (optional): nginx requires a DNS server to resolve the forwarded servers; if this value is not set, it will be guessed automatically from `/etc/resolv.conf`.
## Test using docker-compose
A [`docker-compose.yml`](docker-compose.yml) is included in the repo, so the image is easy to run and test.
```bash
docker-compose up -d # Start the containers
sleep 5 # Wait for containers to start
curl http://127.0.0.1:8080/index.html # Returns Name: frontend, GET /index.html HTTP/1.1
curl http://127.0.0.1:8080/api/test # Returns Name: backend, GET /api/test HTTP/1.1
docker-compose rm -sf # Stop and remove the containers
```
## Repositories
This image is available in the following repositories:
* [Docker Hub](https://hub.docker.com/repository/docker/okelet/front-back-gateway)
* [AWS Public ECR](https://gallery.ecr.aws/okelet/front-back-gateway)
* [GitHub Packages](https://github.com/okelet/front-back-gateway/pkgs/container/front-back-gateway)