Uploading 1-2mb files works fine. When I attempt to upload 16mb file, i get 502 error after several seconds
More detalied:
def upload(request):
if request.method == 'POST':
f = File(data=request.FILES['file'])
f.save()
return redirect(reverse(display), f.id)
else:
return render('filehosting_upload.html', request)
render(template, request [,data]) is my own shorthand that deals with some ajax stuff;
The filehosting_upload.html
:
{% extends "base.html" %}
{% block content %}
<h2>File upload</h2>
<form action="{% url nexus.filehosting.views.upload %}" method="post" enctype="multipart/form-data">
{% csrf_token %}
<input type="file" name="file">
<button type="submit" class="btn">Upload</button>
</form>
{% endblock %}
There are nothing informative in logs i can find.
Versions:
Command line parameters
command=/var/www/ernado/data/envs/PROJECT_NAME/bin/gunicorn -b localhost:8801 -w 4 PROJECT_NAME:application
Nginx configuration for related location:
location /files/upload {
client_max_body_size 100m;
proxy_pass http://HOST;
proxy_connect_timeout 300s;
proxy_read_timeout 300s;
}
2013/03/23 19:31:06 [error] 12701#0: *88 upstream prematurely closed connection while reading response header from upstream, client: MY_IP, server: HOST, request: "POST /files/upload HTTP/1.1", upstream: "http://127.0.0.1:8801/files/upload", host: "HOST", referrer: "http://HOST/files/upload"
2013-03-23 19:31:06 [12634] [CRITICAL] WORKER TIMEOUT (pid:12829)
2013-03-23 19:31:06 [12634] [CRITICAL] WORKER TIMEOUT (pid:12829)
2013-03-23 19:31:06 [13854] [INFO] Booting worker with pid: 13854
Update 1 Tried suggested config
gunicorn --workers=3 --worker-class=tornado --timeout=90 --graceful-timeout=10 --log-level=DEBUG --bind localhost:8801 --debug
Works fine for me now.
The HyperText Transfer Protocol (HTTP) 502 Bad Gateway server error response code indicates that the server, while acting as a gateway or proxy, received an invalid response from the upstream server.
By default, Gunicorn creates a TCP socket located at 127.0. 0.1:8000. You can override this default by using Gunicorn's --bind switch to designate a different location—a different TCP socket, a Unix socket, or a file descriptor. The command shown here starts Gunicorn on the localhost using port 4999.
I run my gunicorn with that parameters, try :
python manage.py run_gunicorn --workers=3 --worker-class=tornado --timeout=90 --graceful-timeout=10 --log-level=DEBUG --bind 127.0.0.1:8151 --debug
or if you run differently, you may run with that options
For large files handling you should use a worker-class. Also I had some trouble using gevent in python 3.7, better to use 3.6.
Django, Python 3.6 example:
Install:
pip install gevent
Run
gunicorn --chdir myApp myApp.wsgi --workers 4 --worker-class=gevent --bind 0.0.0.0:80 --timeout=90 --graceful-timeout=10
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With