An open API service indexing awesome lists of open source software.

https://github.com/denisetiya/nginx-gateway

A reusable and production-ready API Gateway built on Nginx with: Automatic SSL (Let’s Encrypt), Rate limiting, Easy service registration scripts, Full Docker Compose setup
https://github.com/denisetiya/nginx-gateway

api-gateway config docker docker-compose nginx nginx-api-gateway server-configuration

Last synced: about 2 months ago
JSON representation

A reusable and production-ready API Gateway built on Nginx with: Automatic SSL (Let’s Encrypt), Rate limiting, Easy service registration scripts, Full Docker Compose setup

Awesome Lists containing this project

README

          

# πŸš€ Nginx API Gateway with Rate Limiting & Auto SSL

[![Nginx](https://img.shields.io/badge/Nginx-1.27+-green?logo=nginx\&logoColor=white)](https://nginx.org/)
[![Docker](https://img.shields.io/badge/Docker-Compose-blue?logo=docker\&logoColor=white)](https://docs.docker.com/compose/)
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](./LICENSE)
[![SSL](https://img.shields.io/badge/SSL-Auto%20Renewal-success?logo=letsencrypt)](https://letsencrypt.org/)
[![Rate Limit](https://img.shields.io/badge/Rate--Limiting-10r/s-orange)](#rate-limiting)

A **reusable** and **production-ready** API Gateway built on **Nginx** with:

- βœ… Automatic SSL (**Let’s Encrypt**)
- βœ… Rate limiting per IP
- βœ… Easy service registration scripts
- βœ… Full **Docker Compose** setup

---

## ⛩️ Architecture

```mermaid
graph TD
A[Client] --> B(Nginx API Gateway)
B --> C{Rate Limiting}
C --> D[Service 1]
C --> E[Service 2]
C --> F[Service N]

B --> G[(SSL Termination)]
G --> H[Let's Encrypt]

subgraph "API Gateway"
B
C
G
end

subgraph "Services"
D
E
F
end

subgraph "Security"
H
end
```

## ✨ Features

* πŸ”’ **Security by default** β†’ SSL, security headers, CORS
* ⚑ **Rate limiting** β†’ 10 r/s per IP (burst 20)
* 🐳 **Dockerized** β†’ Ready to deploy with `docker-compose`
* πŸ› οΈ **Easy service config** β†’ Add new APIs with a single script

---

## πŸ“‹ Prerequisites

* [Docker](https://docs.docker.com/get-docker/) & [Docker Compose](https://docs.docker.com/compose/)
* A domain name pointing to your server

---

## βš™οΈ Setup Instructions

1. **Configure Docker Compose**
Edit [`docker-compose.yml`](./docker-compose.yml):

* Replace `your-email@example.com`
* Replace `your-domain.com`

2. **Start the gateway**

```bash
docker-compose up -d
```

3. **Add new services**
Linux/Mac:

```bash
./add-service.sh SERVICE_NAME SERVICE_PORT SERVICE_PREFIX DOMAIN
```

Windows:

```cmd
add-service.bat SERVICE_NAME SERVICE_PORT SERVICE_PREFIX DOMAIN
```

Example:

```bash
./add-service.sh user-service 3000 /api/users example.com
```

4. **Restart Nginx**

```bash
docker-compose restart nginx
```

---

## πŸ”§ Configuration

### Rate Limiting

```nginx
limit_req_zone $binary_remote_addr zone=api:10m rate=10r/s;
```

* Default: `10r/s` per IP
* Burst: `20 requests`
* Zone size: `10MB (~160k IPs)`

### SSL

```nginx
ssl_protocols TLSv1.2 TLSv1.3;
ssl_ciphers HIGH:!aNULL:!MD5;
```

* Certificates managed by **Certbot**
* Stored in `/ssl`
* Auto renewal enabled

---

## 🐞 Troubleshooting

* **Check SSL logs**

```bash
docker-compose logs certbot
```
* **Test Nginx config**

```bash
docker-compose exec nginx nginx -t
```
* **Check rate limit logs**

```bash
docker-compose logs nginx
```

---

## πŸ“‚ Directory Structure

```
nginx-gateway/
β”œβ”€β”€ docker-compose.yml # Docker Compose config
β”œβ”€β”€ nginx.conf # Main Nginx config
β”œβ”€β”€ conf.d/ # Service configs
β”‚ └── service-template.conf
β”œβ”€β”€ ssl/ # SSL certificates
β”œβ”€β”€ www/ # Certbot webroot
β”‚ └── rate-limit.html
β”œβ”€β”€ logs/ # Nginx logs
β”œβ”€β”€ add-service.sh # Add service (Linux/Mac)
└── add-service.bat # Add service (Windows)
```

---

## πŸ“– Example Usage

See [example-usage.md](./example-usage.md) for real service integration examples.

---

## πŸ“œ License

This project is open source and available under the MIT License. See the [LICENSE](LICENSE) file for more information.

---