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

https://github.com/solomonkassa/nginx-automation

๐Ÿš€ NGINX Automation Framework A comprehensive, enterprise-grade NGINX automation framework designed for high-availability, security-focused, and scalable web infrastructure deployment.
https://github.com/solomonkassa/nginx-automation

ansible ci-cd doker kubernetes nginx nginx-docker prometheus script security shell-script

Last synced: 2 months ago
JSON representation

๐Ÿš€ NGINX Automation Framework A comprehensive, enterprise-grade NGINX automation framework designed for high-availability, security-focused, and scalable web infrastructure deployment.

Awesome Lists containing this project

README

          

# ๐Ÿš€ NGINX Automation Framework

A comprehensive, enterprise-grade NGINX automation framework designed for high-availability, security-focused, and scalable web infrastructure deployment.

[![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](https://opensource.org/licenses/MIT)
[![GitHub Release](https://img.shields.io/github/v/release/your-org/nginx-automation)](https://github.com/Solomonkassa/nginx-automation/releases)
[![Build Status](https://img.shields.io/jenkins/build?jobUrl=https%3A%2F%2Fjenkins.example.com%2Fjob%2Fnginx-automation)](https://jenkins.example.com/job/nginx-automation)
[![Security Scan](https://img.shields.io/badge/security-scan-brightgreen)](SECURITY.md)
[![Documentation](https://img.shields.io/badge/docs-comprehensive-blue)](https://docs.example.com/nginx-automation)

## ๐Ÿ“‹ Table of Contents

- [Overview](#overview)
- [Key Features](#key-features)
- [Architecture](#architecture)
- [Quick Start](#quick-start)
- [Installation](#installation)
- [Configuration](#configuration)
- [Deployment](#deployment)
- [Monitoring](#monitoring)
- [Security](#security)
- [CI/CD Integration](#cicd-integration)
- [Disaster Recovery](#disaster-recovery)
- [Contributing](#contributing)
- [License](#license)
- [Support](#support)

## ๐ŸŒŸ Overview

This framework provides a complete, production-ready solution for automating NGINX deployment and management across various environments. It incorporates industry best practices for security, performance, and reliability.

**Purpose**: Streamline NGINX infrastructure provisioning, configuration management, certificate automation, monitoring, and disaster recovery processes.

**Target Environments**: Production, Staging, Development, and Disaster Recovery sites.

## ๐Ÿš€ Key Features

### ๐Ÿ”’ **Security**
- Automatic SSL/TLS certificate management (Let's Encrypt)
- WAF (Web Application Firewall) integration with OWASP Core Rule Set
- Security headers enforcement (CSP, HSTS, X-Frame-Options)
- Rate limiting and DDoS protection
- Regular security scanning and vulnerability assessment

### โšก **Performance**
- Optimized caching strategies
- HTTP/2 and HTTP/3 support
- Gzip/Brotli compression
- Load balancing with health checks
- Connection pooling and keep-alive optimization

### ๐Ÿ”„ **Automation**
- Infrastructure as Code (Terraform)
- Configuration Management (Ansible)
- Container Orchestration (Kubernetes/Docker)
- Automated certificate renewal
- Zero-downtime deployments

### ๐Ÿ“Š **Monitoring & Observability**
- Real-time metrics with Prometheus
- Comprehensive dashboards with Grafana
- Structured JSON logging
- Distributed tracing support
- Alerting with multiple notification channels

### ๐Ÿ”ง **High Availability**
- Multi-zone/multi-region deployments
- Automated failover and recovery
- Blue-green deployment support
- Rolling updates with health checks
- Backup and restore automation

## ๐Ÿ— Architecture

### Infrastructure Diagram
```mermaid
graph TB
A[Client Requests] --> B[Cloud Load Balancer]
B --> C[NGINX Layer 1
Edge Proxies]
C --> D[NGINX Layer 2
Application Proxies]
D --> E[Backend Services]

F[Monitoring] --> C
F --> D
F --> E

G[CI/CD Pipeline] --> H[Configuration Repository]
H --> I[Deployment Manager]
I --> C
I --> D

J[Security Scanner] --> H
K[Certificate Manager] --> C
K --> D
```

### Directory Structure
```
nginx-automation/
โ”œโ”€โ”€ terraform/ # Infrastructure as Code
โ”‚ โ”œโ”€โ”€ main.tf
โ”‚ โ”œโ”€โ”€ variables.tf
โ”‚ โ”œโ”€โ”€ outputs.tf
โ”‚ โ””โ”€โ”€ modules/
โ”‚ โ”œโ”€โ”€ network/
โ”‚ โ”œโ”€โ”€ compute/
โ”‚ โ””โ”€โ”€ security/
โ”œโ”€โ”€ ansible/ # Configuration Management
โ”‚ โ”œโ”€โ”€ playbooks/
โ”‚ โ”‚ โ”œโ”€โ”€ deploy-nginx.yml
โ”‚ โ”‚ โ”œโ”€โ”€ security-harden.yml
โ”‚ โ”‚ โ””โ”€โ”€ cert-renew.yml
โ”‚ โ”œโ”€โ”€ roles/
โ”‚ โ”‚ โ”œโ”€โ”€ nginx/
โ”‚ โ”‚ โ”œโ”€โ”€ monitoring/
โ”‚ โ”‚ โ””โ”€โ”€ security/
โ”‚ โ””โ”€โ”€ inventories/
โ”‚ โ”œโ”€โ”€ production/
โ”‚ โ”œโ”€โ”€ staging/
โ”‚ โ””โ”€โ”€ development/
โ”œโ”€โ”€ docker/ # Containerization
โ”‚ โ”œโ”€โ”€ Dockerfile
โ”‚ โ”œโ”€โ”€ docker-compose.yml
โ”‚ โ”œโ”€โ”€ docker-compose.prod.yml
โ”‚ โ””โ”€โ”€ entrypoint.sh
โ”œโ”€โ”€ kubernetes/ # Kubernetes Manifests
โ”‚ โ”œโ”€โ”€ namespaces/
โ”‚ โ”œโ”€โ”€ deployments/
โ”‚ โ”œโ”€โ”€ services/
โ”‚ โ”œโ”€โ”€ configmaps/
โ”‚ โ”œโ”€โ”€ secrets/
โ”‚ โ””โ”€โ”€ helm/
โ”‚ โ””โ”€โ”€ nginx/
โ”‚ โ”œโ”€โ”€ Chart.yaml
โ”‚ โ”œโ”€โ”€ values.yaml
โ”‚ โ””โ”€โ”€ templates/
โ”œโ”€โ”€ configs/ # NGINX Configurations
โ”‚ โ”œโ”€โ”€ nginx.conf
โ”‚ โ”œโ”€โ”€ conf.d/
โ”‚ โ”‚ โ”œโ”€โ”€ security.conf
โ”‚ โ”‚ โ”œโ”€โ”€ caching.conf
โ”‚ โ”‚ โ”œโ”€โ”€ compression.conf
โ”‚ โ”‚ โ””โ”€โ”€ logging.conf
โ”‚ โ”œโ”€โ”€ sites-available/
โ”‚ โ”‚ โ”œโ”€โ”€ app1.example.com.conf
โ”‚ โ”‚ โ””โ”€โ”€ app2.example.com.conf
โ”‚ โ””โ”€โ”€ templates/
โ”‚ โ”œโ”€โ”€ nginx.conf.j2
โ”‚ โ””โ”€โ”€ site.conf.j2
โ”œโ”€โ”€ scripts/ # Automation Scripts
โ”‚ โ”œโ”€โ”€ deploy.sh
โ”‚ โ”œโ”€โ”€ health-check.sh
โ”‚ โ”œโ”€โ”€ cert-automation.sh
โ”‚ โ”œโ”€โ”€ backup.sh
โ”‚ โ”œโ”€โ”€ restore.sh
โ”‚ โ”œโ”€โ”€ security-scan.sh
โ”‚ โ””โ”€โ”€ performance-test.sh
โ”œโ”€โ”€ monitoring/ # Monitoring Stack
โ”‚ โ”œโ”€โ”€ prometheus/
โ”‚ โ”‚ โ”œโ”€โ”€ prometheus.yml
โ”‚ โ”‚ โ”œโ”€โ”€ alert.rules
โ”‚ โ”‚ โ””โ”€โ”€ dashboard.yml
โ”‚ โ”œโ”€โ”€ grafana/
โ”‚ โ”‚ โ”œโ”€โ”€ dashboards/
โ”‚ โ”‚ โ”‚ โ”œโ”€โ”€ nginx-overview.json
โ”‚ โ”‚ โ”‚ โ”œโ”€โ”€ security.json
โ”‚ โ”‚ โ”‚ โ””โ”€โ”€ performance.json
โ”‚ โ”‚ โ””โ”€โ”€ datasources/
โ”‚ โ”œโ”€โ”€ loki/ # Log aggregation
โ”‚ โ””โ”€โ”€ tempo/ # Tracing
โ”œโ”€โ”€ security/ # Security Configurations
โ”‚ โ”œโ”€โ”€ ssl/
โ”‚ โ”‚ โ”œโ”€โ”€ generate-certs.sh
โ”‚ โ”‚ โ””โ”€โ”€ renew-certs.sh
โ”‚ โ”œโ”€โ”€ waf-rules/
โ”‚ โ”‚ โ”œโ”€โ”€ modsecurity.conf
โ”‚ โ”‚ โ””โ”€โ”€ crs-setup.conf
โ”‚ โ””โ”€โ”€ policies/
โ”‚ โ”œโ”€โ”€ csp.json
โ”‚ โ””โ”€โ”€ rate-limiting.json
โ”œโ”€โ”€ tests/ # Testing Suite
โ”‚ โ”œโ”€โ”€ unit/
โ”‚ โ”‚ โ””โ”€โ”€ nginx-test.bats
โ”‚ โ”œโ”€โ”€ integration/
โ”‚ โ”‚ โ””โ”€โ”€ api-test.sh
โ”‚ โ”œโ”€โ”€ load-test/
โ”‚ โ”‚ โ”œโ”€โ”€ k6-script.js
โ”‚ โ”‚ โ””โ”€โ”€ locustfile.py
โ”‚ โ”œโ”€โ”€ security-scan/
โ”‚ โ”‚ โ”œโ”€โ”€ zap-scan.yml
โ”‚ โ”‚ โ””โ”€โ”€ nmap-scan.sh
โ”‚ โ””โ”€โ”€ compliance/
โ”‚ โ”œโ”€โ”€ pci-dss.yml
โ”‚ โ””โ”€โ”€ gdpr.yml
โ”œโ”€โ”€ ci-cd/ # CI/CD Pipelines
โ”‚ โ”œโ”€โ”€ Jenkinsfile
โ”‚ โ”œโ”€โ”€ .gitlab-ci.yml
โ”‚ โ”œโ”€โ”€ github-actions.yml
โ”‚ โ””โ”€โ”€ argo-cd/
โ”‚ โ”œโ”€โ”€ application.yaml
โ”‚ โ””โ”€โ”€ project.yaml
โ”œโ”€โ”€ docs/ # Documentation
โ”‚ โ”œโ”€โ”€ architecture.md
โ”‚ โ”œโ”€โ”€ deployment-guide.md
โ”‚ โ”œโ”€โ”€ security-guide.md
โ”‚ โ”œโ”€โ”€ troubleshooting.md
โ”‚ โ””โ”€โ”€ api-reference.md
โ”œโ”€โ”€ .github/ # GitHub Workflows
โ”‚ โ”œโ”€โ”€ workflows/
โ”‚ โ”œโ”€โ”€ ISSUE_TEMPLATE/
โ”‚ โ””โ”€โ”€ PULL_REQUEST_TEMPLATE/
โ””โ”€โ”€ environments/ # Environment Configs
โ”œโ”€โ”€ production/
โ”œโ”€โ”€ staging/
โ””โ”€โ”€ development/
```

## ๐Ÿš€ Quick Start

### Prerequisites

- Linux/Unix environment (Ubuntu 20.04+ recommended)
- Docker and Docker Compose
- Terraform v1.0+
- Ansible v2.10+
- kubectl and Helm v3+
- Git

### Quick Installation

```bash
# Clone the repository
git clone https://github.com/Solomonkassa/nginx-automation.git
cd nginx-automation

# Setup environment
cp .env.example .env
# Edit .env with your configuration

# Initialize infrastructure
make init

# Deploy development environment
make deploy-dev

# Verify deployment
make verify
```

### Docker Compose Quick Start

```bash
# Start the full stack with Docker Compose
docker-compose -f docker/docker-compose.full.yml up -d

# Check services
docker-compose ps

# View logs
docker-compose logs -f nginx
```

## ๐Ÿ“ฆ Installation

### Detailed Installation Steps

1. **Clone and Setup**
```bash
git clone --branch stable https://github.com/your-org/nginx-automation.git
cd nginx-automation

# Install dependencies
./scripts/setup.sh
```

2. **Configure Environment Variables**
```bash
# Copy and edit environment configuration
cp environments/development/.env.example environments/development/.env
vi environments/development/.env
```

3. **Initialize Infrastructure**
```bash
# Initialize Terraform
cd terraform
terraform init
terraform plan -var-file="../environments/development/terraform.tfvars"
terraform apply -var-file="../environments/development/terraform.tfvars"
```

4. **Configure Ansible**
```bash
cd ../ansible
cp inventories/development/hosts.example inventories/development/hosts
vi inventories/development/hosts

# Test connection
ansible -i inventories/development/hosts all -m ping
```

## โš™๏ธ Configuration

### Core Configuration Files

#### Main NGINX Configuration (`configs/nginx.conf`)
```nginx
# Optimized for production
worker_processes auto;
worker_rlimit_nofile 100000;

events {
worker_connections 4096;
multi_accept on;
use epoll;
}

http {
include /etc/nginx/mime.types;
default_type application/octet-stream;

# Performance tuning
sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 65;
keepalive_requests 1000;

# Security includes
include /etc/nginx/conf.d/security.conf;
include /etc/nginx/conf.d/rate-limiting.conf;

# Site configurations
include /etc/nginx/sites-enabled/*;
}
```

#### Environment-Specific Configuration

Create environment-specific configuration in `environments//`:

```bash
environments/production/
โ”œโ”€โ”€ .env # Environment variables
โ”œโ”€โ”€ terraform.tfvars # Terraform variables
โ”œโ”€โ”€ ansible_vars.yml # Ansible variables
โ”œโ”€โ”€ kustomization.yaml # Kubernetes customization
โ””โ”€โ”€ monitoring/ # Monitoring configs
```

### SSL/TLS Configuration

```bash
# Generate SSL certificates
./scripts/ssl/generate-certs.sh --domain example.com

# Configure automatic renewal
crontab -e
# Add: 0 3 * * * /opt/nginx-automation/scripts/ssl/renew-certs.sh
```

## ๐Ÿš€ Deployment

### Deployment Strategies

#### 1. **Ansible Deployment**
```bash
# Deploy to production
ansible-playbook -i inventories/production/hosts \
playbooks/deploy-nginx.yml \
--extra-vars "@environments/production/ansible_vars.yml"
```

#### 2. **Kubernetes Deployment**
```bash
# Apply Kubernetes manifests
kubectl apply -k kubernetes/overlays/production/

# Verify deployment
kubectl get pods -n nginx-production
kubectl get svc -n nginx-production
```

#### 3. **Blue-Green Deployment**
```bash
# Deploy new version
./scripts/deploy-blue-green.sh --version 2.0.0

# Switch traffic
./scripts/switch-traffic.sh --to green

# Rollback if needed
./scripts/rollback.sh --to blue
```

### CI/CD Pipeline

The framework includes pre-configured pipelines for:

- **Jenkins**: `ci-cd/Jenkinsfile`
- **GitLab CI**: `ci-cd/.gitlab-ci.yml`
- **GitHub Actions**: `.github/workflows/deploy.yml`

Example GitHub Actions workflow:
```yaml
name: Deploy NGINX

on:
push:
branches: [ main ]
pull_request:
branches: [ main ]

jobs:
deploy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Deploy to Production
run: make deploy-prod
env:
KUBECONFIG: ${{ secrets.KUBECONFIG }}
```

## ๐Ÿ“Š Monitoring

### Metrics Collection

The framework includes comprehensive monitoring:

1. **Prometheus Metrics**
- NGINX stub_status metrics
- Custom application metrics
- System metrics (CPU, memory, disk)

2. **Grafana Dashboards**
- NGINX Overview Dashboard
- Security Dashboard
- Performance Dashboard
- Business Metrics Dashboard

### Accessing Dashboards

```bash
# Port forward Grafana
kubectl port-forward svc/grafana 3000:3000 -n monitoring

# Access at http://localhost:3000
# Default credentials: admin / admin
```

### Alerting Configuration

Alerts are configured in `monitoring/prometheus/alerts.yml`:

```yaml
groups:
- name: nginx_alerts
rules:
- alert: HighErrorRate
expr: rate(nginx_http_requests_total{status=~"5.."}[5m]) > 0.05
for: 5m
labels:
severity: critical
annotations:
summary: "High error rate on NGINX"
description: "Error rate is {{ $value }} per second"
```

## ๐Ÿ”’ Security

### Security Features

1. **Automated Security Scanning**
```bash
# Run security scan
./scripts/security-scan.sh --full

# Check for vulnerabilities
trivy image nginx:1.24.0
```

2. **Compliance Checks**
```bash
# Run compliance checks
./scripts/compliance-check.sh --standard pci-dss
```

3. **Secret Management**
```bash
# Store secrets securely
ansible-vault encrypt environments/production/secrets.yml
```

### Security Headers

Automatically configured security headers:
- Content-Security-Policy (CSP)
- Strict-Transport-Security (HSTS)
- X-Content-Type-Options
- X-Frame-Options
- Referrer-Policy
- Permissions-Policy

## ๐Ÿšจ Disaster Recovery

### Backup Strategy

```bash
# Create backup
./scripts/backup.sh --full

# Restore from backup
./scripts/restore.sh --backup-file backup-20231201.tar.gz
```

### Recovery Procedures

1. **Infrastructure Recovery**
```bash
# Recreate infrastructure
terraform apply -var-file="environments/dr/terraform.tfvars"
```

2. **Configuration Recovery**
```bash
# Restore configurations
ansible-playbook playbooks/restore-config.yml
```

3. **Data Recovery**
```bash
# Restore data from backup
./scripts/restore-data.sh --from-s3
```

## ๐Ÿงช Testing

### Test Suite

```bash
# Run all tests
make test-all

# Specific test types
make test-unit # Unit tests
make test-integration # Integration tests
make test-load # Load tests
make test-security # Security tests
```

### Load Testing with k6

```javascript
// tests/load-test/script.js
import http from 'k6/http';
import { check, sleep } from 'k6';

export let options = {
stages: [
{ duration: '30s', target: 100 },
{ duration: '1m', target: 500 },
{ duration: '30s', target: 0 },
],
thresholds: {
http_req_duration: ['p(95)<500'],
http_req_failed: ['rate<0.01'],
},
};

export default function () {
let res = http.get('https://example.com');
check(res, {
'status is 200': (r) => r.status === 200,
'response time < 500ms': (r) => r.timings.duration < 500,
});
sleep(1);
}
```

## ๐Ÿค Contributing

We welcome contributions! Please see our [Contributing Guide](CONTRIBUTING.md) for details.

### Development Workflow

1. Fork the repository
2. Create a feature branch
3. Make your changes
4. Run tests
5. Submit a pull request

### Code Standards

- Follow existing code style
- Write comprehensive tests
- Update documentation
- Keep commits atomic

## ๐Ÿ“„ License

This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.

## ๐Ÿ†˜ Support

### Getting Help

- ๐Ÿ“š [Documentation](https://docs.example.com/nginx-automation)
- ๐Ÿ› [Issue Tracker](https://github.com/your-org/nginx-automation/issues)
- ๐Ÿ’ฌ [Slack Channel](https://slack.example.com/nginx-automation)
- ๐Ÿ“ง [Email Support](mailto:support@example.com)

### Common Issues

Check our [Troubleshooting Guide](docs/troubleshooting.md) for common problems and solutions.

### Commercial Support

For enterprise support, contact [enterprise@example.com](mailto:enterprise@example.com).

## ๐ŸŽฏ Roadmap

- [x] Initial release with core features
- [ ] Multi-cloud support (AWS, GCP, Azure)
- [ ] Service mesh integration (Istio, Linkerd)
- [ ] AI-powered anomaly detection
- [ ] GitOps workflow enhancement
- [ ] Extended compliance frameworks (SOC2, ISO27001)

## ๐Ÿ“ˆ Performance Benchmarks

| Metric | Value | Target |
|--------|-------|--------|
| Requests/sec | 15,000 | 10,000 |
| Latency (p95) | 45ms | 100ms |
| Availability | 99.99% | 99.95% |
| Error Rate | 0.01% | 0.1% |

---

## ๐Ÿ† Acknowledgments

- NGINX Inc. for the amazing web server
- The open-source community for various tools and libraries
- Our contributors and maintainers

## ๐Ÿ”— Related Projects

- [nginx-prometheus-exporter](https://github.com/nginxinc/nginx-prometheus-exporter)
- [cert-manager](https://cert-manager.io/)
- [prometheus-nginx-exporter](https://github.com/discordianfish/nginx-exporter)

---

**Maintained by**: Solomon Kassa
**Last Updated**: January 2026
**Version**: 1.0.0

---


Need help? Check our FAQ or open an issue


Built with โค๏ธ by Solomon Kassa