I've set up a docker-compose with wordpress, nginx and mysql containers.
Everything is working fine besides the uploading of images. When I upload images they don't get saved in either of the container's /uploads folder, and just show a blank image on wp-admin.
If I try to access the image url directly it returns 404.
I've found 3 (post 1, post 2 & post 3) related posts, but none of them gave me any insights to this problem.
This is my docker-compose:
version: '3.1'
services:
wordpress:
image: wordpress:fpm-alpine
depends_on:
- db
restart: always
env_file:
- .env
ports:
- 9000:9000
environment:
WORDPRESS_DB_HOST: db
WORDPRESS_DB_USER: ${DB_USER}
WORDPRESS_DB_PASSWORD: ${DB_PASSWORD}
WORDPRESS_DB_NAME: ${DB}
WORDPRESS_DEBUG: ${DEBUG}
WORDPRESS_DEBUG_DISPLAY: ${DEBUG}
WORDPRESS_DEBUG_LOG: ${DEBUG}
volumes:
- ./theme-folder:/var/www/html/wp-content/themes/theme-folder
db:
image: mysql:5.7
restart: always
env_file:
- .env
environment:
MYSQL_DATABASE: ${DB}
MYSQL_USER: ${DB_USER}
MYSQL_PASSWORD: ${DB_PASSWORD}
MYSQL_ROOT_PASSWORD: ${DB_ROOT_PASSWORD}
volumes:
- db:/var/lib/mysql
webserver:
image: nginx:alpine
depends_on:
- wordpress
ports:
- 8080:80
- 443:443
volumes:
- ./nginx-conf:/etc/nginx/conf.d
- wordpress:/var/www/html
- ./theme-folder:/var/www/html/wp-content/themes/theme-folder
- ./pem/fullchain.pem:/etc/letsencrypt/live/website/fullchain.pem
- ./pem/privkey.pem:/etc/letsencrypt/live/website/privkey.pem
volumes:
wordpress:
db:
This is my nginx.conf:
server {
listen 80;
listen [::]:80;
server_name website;
root /var/www/html;
index index.php index.html index.htm;
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;
}
location / {
rewrite ^ https://$host$request_uri? permanent;
}
}
server {
listen 443 ssl;
listen [::]:443 ssl;
server_name website;
root /var/www/html;
index index.php index.html index.htm;
ssl_certificate /etc/letsencrypt/live/website/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/website/privkey.pem;
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;
}
}
Really appreciate any insights, I've been stuck here for days now.
Updates
Tried tailing docker logs, but didn't help much.
Also, tried adding this to my nginx.conf:
location ~* \.(css|gif|ico|jpeg|jpg|js|png)$ {
expires max;
log_not_found off;
}