May 6th, 2023
WordPress + Docker + Nginx + SSL
Start wordpres on Nginx under the Docker container
In case of easy steps to install SSL certificate, you ZeroSSL and create new certificate.
It is valid for 90 days for free.
// Create the SSL certificate
// https://mpolinowski.github.io/docs/DevOps/NGINX/2020-08-27--nginx-docker-ssl-certs-self-signed/2020-08-27/#creating-the-ssl-certificate
sudo openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout /opt/docker-ingress/configuration/ssl/nginx-selfsigned.key -out /opt/docker-ingress/configuration/ssl/nginx-selfsigned.crt
// uploads.ini
file_uploads = On
memory_limit = 512M
upload_max_filesize = 256M
post_max_size = 256M
max_execution_time = 300
max_input_time = 1000
// .env
MYSQL_ROOT_PASSWORD=wordpress_root
MYSQL_USER=wordpress
MYSQL_PASSWORD=wordpress
// docker-compose.yml
version: '3'
services:
db:
image: mysql:8.0
container_name: db
restart: unless-stopped
env_file: .env
environment:
- MYSQL_DATABASE=wordpress
volumes:
- mysql_data:/var/lib/mysql
command: '--default-authentication-plugin=mysql_native_password'
networks:
- app-network
wordpress:
depends_on:
- db
image: wordpress:6.2.0-fpm-alpine
container_name: wordpress
restart: unless-stopped
env_file: .env
environment:
- WORDPRESS_DB_HOST=db:3306
- WORDPRESS_DB_USER=$MYSQL_USER
- WORDPRESS_DB_PASSWORD=$MYSQL_PASSWORD
- WORDPRESS_DB_NAME=wordpress
volumes:
- ./wordpress_data:/var/www/html
- ./uploads.ini:/usr/local/etc/php/conf.d/uploads.ini
networks:
- app-network
webserver:
depends_on:
- wordpress
image: nginx:stable-alpine
container_name: webserver
restart: unless-stopped
ports:
- "80:80"
- "443:443"
volumes:
- ./configuration/conf.d:/etc/nginx/conf.d
- ./configuration/ssl:/etc/nginx/ssl
- ./configuration/conf.d/nginx.conf:/etc/nginx/conf.d/nginx.conf
- ./wordpress_data:/var/www/html
networks:
- app-network
volumes:
mysql_data:
networks:
app-network: {}
# driver: bridge
// nginx.conf
server {
listen 443 ssl;
listen [::]:443 ssl;
ssl_certificate /etc/nginx/ssl/certificate.crt;
ssl_certificate_key /etc/nginx/ssl/private.key;
include /etc/nginx/ssl/ssl-params.conf;
server_name ibliv.com www.ibliv.com;
index index.php index.html index.htm;
root /var/www/html;
location ~ /.well-known/acme-challenge {
allow all;
root /var/www/html;
}
location / {
try_files $uri $uri/ /index.php$is_args$args;
}
location ~ \.php$ {
try_files $uri =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass wordpress:9000;
fastcgi_index index.php;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_path_info;
}
location ~ /\.ht {
deny all;
}
location = /favicon.ico {
log_not_found off; access_log off;
}
location = /robots.txt {
log_not_found off; access_log off; allow all;
}
location ~* \.(css|gif|ico|jpeg|jpg|js|png)$ {
expires max;
log_not_found off;
}
}
server {
listen 80;
listen [::]:80;
server_name ibliv.com www.ibliv.com;
return 301 https://$server_name$request_uri;
}
# Start the docker
docker compose up -d
# List the containers
docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
82bfa6789358 nginx:latest "/docker-entrypoint.…" 9 minutes ago Up 9 minutes 0.0.0.0:80->80/tcp, :::80->80/tcp webserver
4bcf3e01fb98 wordpress:6.2.0-fpm-alpine "docker-entrypoint.s…" 9 minutes ago Up 9 minutes 9000/tcp wordpress
3cd895c69c4f mysql:8.0 "docker-entrypoint.s…" 47 minutes ago Up 47 minutes 3306/tcp, 33060/tcp db
Leave a Reply