2

I need to configure nginx + gunicorn to be able to upload files greater than the default max size in both servers.

My nginx .conf file looks like this:

server {
    # ...

    location / {
        proxy_pass_header Server;
        proxy_set_header Host $http_host;
        proxy_redirect   off;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Scheme  $scheme;
        proxy_connect_timeout 60;
        proxy_pass http://localhost:8000/;
    }
}

The idea is to allow requests of 20M for two locations:

  • /admin/path/to/upload?param=value
  • /installer/other/path/to/upload?param=value

I've tried to add location directives at the same level than the one I've pasted here (getting 404 errors) and also tried to add them inside the location / directive (getting 413 Entity Too Large errors).

My location directives look like these in their simplest form:

location /admin/path/to/upload/ {
    client_max_body_size 20M;
}
location /installer/other/path/to/upload/ {
    client_max_body_size 20M;
}

But they don't work (actually I tested lots of combinations and I'm desperate thinking about this.

Please, help If you can: What settings do I need to set to make this work?

Thank you so much!

carlosescri
  • 171
  • 1
  • 2
  • 6

2 Answers2

5

This finally worked doing something like this:

location / {
    proxy_pass_header Server;
    proxy_set_header Host $http_host;
    proxy_redirect   off;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-Scheme  $scheme;
    proxy_set_header X-Forwarded-Protocol ssl;
    proxy_connect_timeout 120;
    proxy_pass http://localhost:8000/;

    location /admin/path/to/upload {
        client_max_body_size 50m;
        proxy_pass http://localhost:8000/admin/path/to/upload;
    }
}
carlosescri
  • 171
  • 1
  • 2
  • 6
0

Sounds like it was almost working when you had the client_max_body_size in the non-root locations. Have you also set dav_methods PUT; in your nginx conf to enable PUT and DELETE requests?

chrskly
  • 1,569
  • 12
  • 16
  • Thank you for your answer @chrskly. The method used to upload the files is POST so I think there is no need for adding the `dav_methods` setting. Please, correct me if I'm wrong. – carlosescri Jun 12 '13 at 13:42