-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #23 from YuriiDorosh/features/redis
Features/redis
- Loading branch information
Showing
5 changed files
with
257 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
# Production Docker Configuration for CodeIgniter 4 Application | ||
# ============================================================= | ||
# | ||
# This Docker Compose configuration is designed for production deployment of a | ||
# CodeIgniter 4 application. It defines four main services: the application itself (`app`), | ||
# an Nginx web server (`nginx`), a MySQL database (`mysql`), and a Redis cache (`redis`). | ||
# Each service is configured with production in mind, using Alpine images where available | ||
# for their smaller footprint and setting environment variables for secure and efficient operation. | ||
# | ||
# Usage: | ||
# ------ | ||
# Before running, ensure you have set the environment variables `MYSQL_PROD_DATABASE`, | ||
# `MYSQL_PROD_USER`, and `MYSQL_PROD_PASSWORD` for the MySQL service. These can be set | ||
# in an `.env` file located in the same directory as this docker-compose file or exported | ||
# directly in your shell. | ||
# | ||
# To start all services in detached mode, use: | ||
# `docker-compose -f docker-compose.prod.yml up -d` | ||
# | ||
# To stop all services and remove containers, networks, and volumes created by `up`, use: | ||
# `docker-compose -f docker-compose.prod.yml down` | ||
# | ||
# Services: | ||
# --------- | ||
# app: The main application service built from a Dockerfile located in `./docker/ci4`. | ||
# It's configured to run in a `production` environment. The entire application directory | ||
# is mounted into the container to facilitate easy updates, but consider using COPY | ||
# in Dockerfile for a more secure, immutable deployment. | ||
# | ||
# nginx: Serves as the web server, using the lightweight Alpine Linux version of Nginx. | ||
# It serves static files directly and proxies PHP requests to the `app` service. | ||
# The production Nginx configuration is mounted from `./docker/nginx/nginx.prod.conf`. | ||
# | ||
# mysql: The MySQL database service, crucial for data persistence. It's configured through | ||
# environment variables for the database name, user, and password, which should be | ||
# securely managed. Data is persisted in a Docker volume named `mysql-data`. | ||
# | ||
# redis: Used for caching and session storage to enhance application performance. | ||
# Like Nginx, it uses an Alpine Linux image for a smaller footprint. | ||
# | ||
# Networks: | ||
# --------- | ||
# app-network: A custom bridge network that facilitates communication between services. | ||
# All services are attached to this network. | ||
# | ||
# Volumes: | ||
# -------- | ||
# mysql-data: A Docker-managed volume that ensures the persistence of MySQL data across | ||
# container restarts and deployments. | ||
# | ||
# Notes: | ||
# ------ | ||
# - This configuration is optimized for production use, but security and performance | ||
# tuning is an ongoing process. Always keep your images up to date and monitor | ||
# for any potential security vulnerabilities. | ||
# - Ensure SSL/TLS configuration for Nginx if exposing services directly to the internet. | ||
# Consider using a service like Let's Encrypt for free SSL certificates. | ||
# | ||
version: '3.8' | ||
services: | ||
app: | ||
build: | ||
context: ./docker/ci4 | ||
volumes: | ||
- .:/var/www/html | ||
environment: | ||
CI_ENVIRONMENT: production | ||
networks: | ||
- app-network | ||
|
||
nginx: | ||
image: nginx:alpine # Using the alpine version for smaller size | ||
volumes: | ||
- ./public:/var/www/html/public | ||
- ./docker/nginx/nginx.prod.conf:/etc/nginx/conf.d/default.conf | ||
networks: | ||
- app-network | ||
depends_on: | ||
- app | ||
|
||
mysql: | ||
image: mysql:5.7 | ||
environment: | ||
MYSQL_DATABASE: ${MYSQL_PROD_DATABASE} | ||
MYSQL_USER: ${MYSQL_PROD_USER} | ||
MYSQL_PASSWORD: ${MYSQL_PROD_PASSWORD} | ||
networks: | ||
- app-network | ||
|
||
redis: | ||
image: redis:alpine # Using the alpine version for smaller size | ||
networks: | ||
- app-network | ||
|
||
networks: | ||
app-network: | ||
driver: bridge | ||
|
||
volumes: | ||
mysql-data: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
server { | ||
listen 80; | ||
# Strongly recommended to also configure listening on 443 (SSL) for HTTPS | ||
# listen 443 ssl; | ||
# ssl_certificate /path/to/your_certificate.pem; | ||
# ssl_certificate_key /path/to/your_private.key; | ||
|
||
server_name example.com; # Change this to your domain | ||
|
||
root /var/www/html/public; | ||
index index.php index.html index.htm; | ||
|
||
# Serve static files directly without passing to PHP | ||
location ~* \.(jpg|jpeg|gif|css|png|js|ico|html)$ { | ||
access_log off; | ||
expires max; | ||
} | ||
|
||
# Deny access to sensitive files | ||
location ~ /\.ht { | ||
deny all; | ||
} | ||
|
||
# URL rewrites and forwarding to index.php | ||
location / { | ||
try_files $uri $uri/ /index.php?$query_string; | ||
} | ||
|
||
# PHP FPM configuration | ||
location ~ \.php$ { | ||
try_files $uri /index.php =404; | ||
fastcgi_pass app:9000; | ||
fastcgi_index index.php; | ||
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; | ||
include fastcgi_params; | ||
} | ||
|
||
# Recommended: security headers | ||
add_header X-Frame-Options "SAMEORIGIN" always; | ||
add_header X-Content-Type-Options "nosniff" always; | ||
add_header X-XSS-Protection "1; mode=block" always; | ||
|
||
# Further optimizations and security settings can be added here | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters