File uploads and client_max_body_size in nginx + gunicorn + django
12,962
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;
}
}
Related videos on Youtube
Author by
carlosescri
Updated on September 18, 2022Comments
-
carlosescri almost 2 years
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 thelocation /
directive (getting413 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 about 11 yearsThank 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. -
manugupt1 over 8 yearsclient_max_body_size 0M; will remove size restrictions
-
carlosescri over 8 yearsThank you for the answer :-) Will be useful for other people.