WordPress Media Upload Error on Docker with Nginx


HTTP error message displayed when upload media on WordPress as shown below


Error message found in nginx error log:
[error] 71#71: *164 client intended to send too large body: 1524386 bytes


WordPress on Docker with Nginx


increase upload size by adding below syntax to nginx.conf:

client_max_body_size 8M;

Step-by-step instructions:-

Step 1) copy original nginx.conf file from nginx container with Docker command

docker cp 98fd0d924718:/etc/nginx/nginx.conf .

Note: replace 98fd0d924718 with your nginx container id

Step 2) open nginx.conf file and add client_max_body_size 8M; between “http {“ and before “log_format”

http {
     include /etc/nginx/mime.types;
     default_type application/octet-stream;
     client_max_body_size 8M;
     log_format main ‘$remote_addr - $remote_user [$time_local] “$request” ‘

Step 3) copy modified nginx.conf file back to nginx container

docker cp nginx.conf 98fd0d924718:/etc/nginx/nginx.conf

Step 4) enter nginx container to restart nginx service

docker exec -it 98fd0d924718 /bin/bash
service nginx reload

Step 5) try to upload again. If you want to increase the size of upload file more than default 2MB, follow this instruction.