Docker: Help needed: 413 Request entity too large despite setting client_max_body_size

Created on 20 Jun 2018  路  4Comments  路  Source: nextcloud/docker

I am trying to use the self-signed example. Unfortunately this lacks the cron so I altered it slightly to add cron and redis, based on the other examples. I'm attaching my docker-compose.yml and nginx.conf file. As you can see I have set my max file size to a high number in nginx, but files bigger than 1 MB fail to sync with message server replied: Request Entity Too Large (and also a 413 code sometimes). I've restarted the containers with docker-compose down and docker-compose up -d. What else can I do to diagnose the issue?

docker-compose.yml.txt
nginx.conf.txt

Most helpful comment

echo "client_max_body_size 10G;" > uploadsize.conf
docker cp uploadsize.conf \ docker restart \

All 4 comments

Well, if anyone is wondering, I solved the problem. The line MAX_UPLOAD_SIZE=10GB in docker-compose.yml is wrong, this variable doesn't actually do anything. Instead, you have to:

  1. Create a proxy folder like in the cron example
  2. Change the line in docker-compose.yml saying image: jwilder/nginx-proxy:alpine to build: ./proxy
  3. Restart the whole thing with docker-compose down and docker-compose up

Explanation:

The issue is, as you may already have discovered, that nginx is deciding that the file is too large and refusing it. By default nginx's limit is 1 MB, which is obviously too small for Nextcloud, so we need to increase this by setting client_max_body_size 10G; in the nginx config. But even though this is already set in the example nginx.conf, the error still happens. This is because there are actually 2 nginx containers in this docker-compose: web (presumably for Nextcloud's web UI) and proxy (which appears to actually handle the file sync). The nginx.conf provided in the example applies only to web, while proxy is the one generating the 413s. I've tried putting the nginx.conf into the proxy container like it was done for web, but this broke the whole assembly. Instead I had to use the separate Dockerfile.

What is happening is that when proxy is built from the Dockerfile, the extra file with the upload size parameter gets copied over to proxy's /etc/nginx/conf.d/. The nginx in proxy reads the contents of this folder in addition to /etc/nginx/nginx.conf and applies any instructions found in them as well (in this case the max body size). Somebody tried to do this through Docker environment variables in the example I link above, but nothing actually handles that environment variable so the example is basically broken. I wish this stuff had been documented somewhere or at least someone had checked the examples to make sure they actually work.

echo "client_max_body_size 10G;" > uploadsize.conf
docker cp uploadsize.conf \ docker restart \

echo "client_max_body_size 10G;" > uploadsize.conf
docker cp uploadsize.conf :/etc/nginx/conf.d/uploadsize.conf
docker restart

Your trick was very useful, thanks.
By the way, is it possible RUN this directive from a dockerfile? and in what moment is executed that command? I mean, is executed when we build the Image?. Thanks again

@rutame

is it possible RUN this directive from a dockerfile

You can add it to the nginx image using COPY uploadsize.conf /etc/nginx/conf.d/uploadsize.conf in the Dockerfile or link a volume containing the config to conf.d during runtime. Just be sure that there are no other configs in it before linking your local copy.

in what moment is executed that command?

If the config is linked, it is executed at nginx service start. You can use service nginx restart if you alter the config during runtime.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

k1ngf15h3r picture k1ngf15h3r  路  3Comments

raimund-schluessler picture raimund-schluessler  路  3Comments

happinesslijian picture happinesslijian  路  3Comments

all-the-good-ones-are-gone picture all-the-good-ones-are-gone  路  3Comments

waldner picture waldner  路  3Comments