Error while adding an image to the db using django panel in production. Using docker, nginx and gunicorn

I did a page with django which give the possibility to the user to access to the django admin panel to add an image into the page. The image is being pull to the database with the models of django.

class Images(models.Model):
    left_arrow= models.ImageField(upload_to="general/arrow/")
    right_arrow= models.ImageField(upload_to="general/arrow/")
    open_complete= models.ImageField(upload_to="general/complete/")
    close_complete= models.ImageField(upload_to="general/complete/")
    untick= models.ImageField(upload_to="general/tick/")
    tick= models.ImageField(upload_to="general/tick/")

This was working perfectly in development because i had this command in the urls file:

if settings.DEBUG:
    urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)

In production i had to errase those lines. The media files that were already in the database are being showed perfectly well, the static and media files are working perfectly. But when a user tries to add an image from the django admin panel an error ocurr.

502 Bad Gateway nginx

Digging into the problem i searched the logs of nginx and are the following:

2024/09/17 19:27:27 [error] code: *36 upstream prematurely closed connection while reading response header from upstream, client: "IP",server: carranzafebre.com, request: "POST /admin/home/images/add/ HTTP/1.1", upstream: "http://127.0.0.1:8000/admin/home/images/add/", host: "carranzafebre.com", referrer: "https://carranzafebre.com/admin/home/images/add/"

I have already change a huge amount of things, but nothing happens with this error. Please i need help. I am ussing the default database of django which is sqlite3.

I tried to change the client_max_body_size into 100m and nothing happens. I tried to change some proxy instructions. I tried to change the amount of workers into 3. And many others.

Back to Top