Ecosyste.ms: Awesome

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

Awesome Lists | Featured Topics | Projects

https://github.com/ar-rostami/wordpress-high-performance-dockerized-stack

A scalable, secure, and optimized Docker-based stack for WordPress. Featuring Nginx with FastCGI caching, PostgreSQL, Redis, Kafka, ClickHouse, and Prometheus/Grafana for monitoring. Includes built-in WAF (ModSecurity) and Fail2Ban for advanced security. Perfect for high-traffic and production environments.
https://github.com/ar-rostami/wordpress-high-performance-dockerized-stack

clickhouse docker docker-compose fail2ban fastcgi grafana high-performance kafka modsecurity modsecurity-nginx nginx-proxy pgsql postgresql prometheus redis waf wordpress wp

Last synced: 3 days ago
JSON representation

A scalable, secure, and optimized Docker-based stack for WordPress. Featuring Nginx with FastCGI caching, PostgreSQL, Redis, Kafka, ClickHouse, and Prometheus/Grafana for monitoring. Includes built-in WAF (ModSecurity) and Fail2Ban for advanced security. Perfect for high-traffic and production environments.

Awesome Lists containing this project

README

        

# WordPress High-Performance Dockerized Stack πŸš€



Sublime's custom image


This repository provides a **high-performance**, **scalable**, and **secure** Docker stack for deploying **WordPress**. It leverages various cutting-edge technologies and optimization techniques to ensure excellent performance, high traffic handling, and strong security.

---

## Key Features 🌟

- **Nginx** as a reverse proxy and web server with **FastCGI** caching for ultra-fast content delivery.
- **PostgreSQL** database for WordPress, providing better scalability and performance over MySQL.
- **Redis** for object caching, improving page load times by reducing database queries.
- **ClickHouse** for real-time data analytics and high-performance querying.
- **Kafka** for efficient real-time event processing and message queue management.
- **Prometheus** for system monitoring and **Grafana** for powerful visual metrics and dashboards.
- **ModSecurity** Web Application Firewall (WAF) for protection against attacks like SQL Injection, XSS, and more.
- **Fail2Ban** to protect against brute-force login attempts and automated attacks.

---

## Architecture Overview πŸ—οΈ

The stack uses the following architecture:

Client -> Nginx (Reverse Proxy) -> PHP-FPM -> WordPress | -> PostgreSQL -> Redis -> Kafka -> Zookeeper -> ClickHouse

---

## Installation & Setup πŸš€

### Prerequisites 🧰

Make sure you have the following tools installed:

- **Docker**: [Install Docker](https://docs.docker.com/get-docker/)
- **Docker Compose**: [Install Docker Compose](https://docs.docker.com/compose/install/)

---

### 1. Clone the Repository πŸ’»

Clone the project to your local machine:
```bash
git clone https://github.com/ar-rostami/WordPress-High-Performance-Dockerized-Stack.git
cd WordPress-High-Performance-Dockerized-Stack
```

------------

### 2. Project Directory Structure πŸ“‚

Here’s how the project is organized:

β”œβ”€β”€ docker-compose.yml
β”œβ”€β”€ nginx/
β”‚ └── nginx.conf
β”œβ”€β”€ php/
β”‚ └── php.ini
β”œβ”€β”€ prometheus/
β”‚ └── prometheus.yml
β”œβ”€β”€ wordpress/
β”‚ └── wp-config.php (generated automatically)
β”œβ”€β”€ certs/ (SSL certificates)
β”œβ”€β”€ fail2ban/
β”‚ └── fail2ban.conf
β”œβ”€β”€ modsec/
β”‚ └── modsec.conf
β”œβ”€β”€ wp-content/ (bind-mounted for uploads)
└── README.md

------------

### 3. Configure Environment Variables βš™οΈ
Create a .env file in the root directory with the following contents:

```
POSTGRES_USER=wp_user
POSTGRES_PASSWORD=wp_password
POSTGRES_DB=wp_database
REDIS_MAXMEMORY=256mb
```
You can adjust the environment variables according to your setup.

------------

### 4. Start the Docker Stack 🚒
Run the following command to start all the services in detached mode:
```bash
docker-compose up -d
```
> **This will start:**
- Nginx (reverse proxy and web server)
- PHP-FPM (for WordPress PHP processing)
- PostgreSQL (as the database)
- Redis (for caching)
- Prometheus (for monitoring)

------------

### 5. Access WordPress πŸŽ‰
Once the stack is running, navigate to your browser and access your WordPress site at:
- **[http://localhost](`http://localhost` "http://localhost")**

Follow the WordPress setup wizard to complete the installation.

------------

### 6. Monitoring and Metrics πŸ“Š
Prometheus will be available at http://localhost:9090 for system monitoring.
Grafana dashboards will be available at http://localhost:3000. Default login: admin/admin.
Customization πŸ”§
Nginx Configuration 🌐
Modify the nginx/nginx.conf file to configure caching, SSL, security headers, and other performance settings.

##### PHP Configuration πŸ–₯️
Customize the php/php.ini file to adjust PHP settings like memory limits, max execution time, and OPcache settings.

##### Prometheus Configuration πŸ“ˆ
You can modify the prometheus/prometheus.yml file to add additional services or adjust monitoring settings.

------------

### 7. Security Considerations πŸ”’
##### 1. Protection Against DDoS 🌐
Cloudflare or similar services can help mitigate DDoS attacks.
Rate limiting is configured in Nginx to block excessive requests.
##### 2. Web Application Firewall (WAF) πŸ”
ModSecurity is enabled to block common attack vectors like SQL Injection, Cross-Site Scripting (XSS), and Command Injection.
##### 3. Fail2Ban Protection 🚫
Fail2Ban is configured to block IP addresses after multiple failed login attempts, mitigating brute-force attacks.
Scalability and High Availability πŸ“ˆ
Scaling with Docker Compose ⚑
To scale the PHP-FPM service, simply run:

```bash
docker-compose up -d --scale php=3
```
> This will spin up multiple instances of PHP to handle increased traffic.

------------

### 8. Kubernetes Support ☸️
For larger production environments, the architecture is ready to be deployed to Kubernetes. You can create Kubernetes manifests to deploy the stack to a Kubernetes cluster for horizontal scaling and high availability.

------------

### 9. Troubleshooting πŸ”§
Useful Docker Commands 🐳
Check logs of a specific service:
```bash
docker-compose logs -f

```
Restart a specific service:
```bash
docker-compose restart

```

------------

### 10. Ensure Volumes Are Correctly Mounted πŸ“
Make sure the following directories are writable and correctly mounted:
- wordpress/
- wp-content/
- postgres-data/
- clickhouse-data/

------------

### 11. Future Improvements πŸš€
- Horizontal Scaling: Support scaling PostgreSQL with read replicas for better availability and performance.
- SSL Automation: Set up automatic SSL certificate renewal using Let’s Encrypt.
- Background Processing: Integrate more Kafka consumers for background task processing.

------------

### 12. Contributors πŸ‘₯
**Contributions are welcome! Feel free to submit pull requests.**