Skip to content

Instantly share code, notes, and snippets.

@marsyang1
Last active July 6, 2022 02:43
Show Gist options
  • Save marsyang1/4d9e44350b3f714b65ce1569e58832a1 to your computer and use it in GitHub Desktop.
Save marsyang1/4d9e44350b3f714b65ce1569e58832a1 to your computer and use it in GitHub Desktop.
wordpress docker
# test env only
# put this file to ./nginx_home
# consider use config generator by https://www.digitalocean.com/community/tools/nginx
user nginx;
worker_processes auto;
error_log /var/log/nginx/error.log notice;
pid /var/run/nginx.pid;
events {
worker_connections 1024;
}
http {
include /etc/nginx/mime.types;
default_type application/octet-stream;
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
access_log /var/log/nginx/access.log main;
sendfile on;
#tcp_nopush on;
keepalive_timeout 65;
#gzip on;
# https://gist.github.com/muhammadghazali/6c2b8c80d5528e3118613746e0041263
# https://nginx.org/en/docs/http/server_names.html
server_names_hash_bucket_size 128;
server_names_hash_max_size 1024;
# digitalocean optimize doc https://www.digitalocean.com/community/tutorials/how-to-optimize-nginx-configuration
client_body_buffer_size 1M;
client_header_buffer_size 32K;
client_max_body_size 8M;
# http://nginx.org/en/docs/http/ngx_http_core_module.html#large_client_header_buffers
# for request client setting
# https://websiteforstudents.com/resolved-400-bad-request-request-header-or-cookie-too-large-via-nginx/
large_client_header_buffers 8 32k;
include /etc/nginx/conf.d/*.conf;
}
; comment text
; test env only
; put this file to ./php_home
max_execution_time = 60
memory_limit = 128M
post_max_size = 10M
upload_max_filesize = 10M
max_input_time = 60
file_uploads = On
safe_mode = Off
# test env only
# put this file to ./nginx_home
# Upstream to abstract backend connection(s) for php
upstream php {
server unix:/tmp/php-cgi.socket;
server wordpress:9000;
}
server {
## Your website name goes here.
server_name domain.tld;
## Your only path reference.
root /var/www/html;
## This should be in your http block and if it is, it's not needed here.
index index.php;
location = /favicon.ico {
log_not_found off;
access_log off;
}
location = /robots.txt {
allow all;
log_not_found off;
access_log off;
}
location / {
# This is cool because no php is touched for static content.
# include the "?$args" part so non-default permalinks doesn't break when using query string
try_files $uri $uri/ /index.php?$args;
}
location ~ \.php$ {
#NOTE: You should have "cgi.fix_pathinfo = 0;" in php.ini
include fastcgi_params;
fastcgi_intercept_errors on;
fastcgi_pass php;
#The following parameter can be also included in fastcgi_params file
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
}
location ~* \.(js|css|png|jpg|jpeg|gif|ico)$ {
expires max;
log_not_found off;
}
}
version: "3.9"
services:
web:
image: nginx:latest
ports:
- 80:80
volumes:
- ./nginx_home/site.conf:/etc/nginx/conf.d/default.conf:ro
- ./nginx_home/nginx.conf:/etc/nginx/nginx.conf:ro
- /etc/localtime:/etc/localtime:ro
volumes_from:
- wordpress
depends_on:
- wordpress
wordpress:
image: wordpress:php8.0-fpm-alpine
volumes:
- ./wordpress_home:/var/www/html
- ./php_home/php.ini:/usr/local/etc/php/conf.d/php.ini
environment:
WORDPRESS_DB_HOST: db:3306
WORDPRESS_DB_USER: wordpress
WORDPRESS_DB_PASSWORD: wordpress
WORDPRESS_DB_NAME: wp
depends_on:
- db
db:
image: mysql:5.7
ports:
- 3306:3306
volumes:
- ./mysql_home:/var/lib/mysql
environment:
MYSQL_ROOT_PASSWORD: 1234
MYSQL_DATABASE: wp
MYSQL_USER: wordpress
MYSQL_PASSWORD: wordpress
command: --character-set-server=utf8mb4 --collation-server=utf8mb4_unicode_ci
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment