0

I've recently deployed a django app on digital ocean. Everything works perfectly fine until I try to create an object containing an image. I get an error saying Server Error (500).

Here is what I've tried to do :

server {
listen 80;
server_name ****;

location = /favicon.ico { access_log off; log_not_found off; }
location /static/ {
    root /home/joseph/hacka;
}

location /media/ {
    root /home/joseph/hacka;
}

location / {
    include proxy_params;
    proxy_pass http://unix:/run/gunicorn.sock;
}
}

Here is my settings.py code :

MEDIA_URL = '/media/'
MEDIA_ROOT = os.path.join(BASE_DIR, 'media/')

Unfortunately, that hasn't work out.
Please help me if you know the anwer to my problem.

Update:
I have found the problem with my code: when I turn debug to True, I get an error saying
errno 13: Permission denied.

However, I don not know how to fix this.

Please help me if you can.

Til
  • 5,150
  • 13
  • 26
  • 34
Fantasmo Clone27
  • 333
  • 1
  • 10
  • 19

3 Answers3

0

I guess your problem is because of the media file. Did you check the media settings?

You need to check in the settings.py

MEDIA_ROOT = os.path.join(BASE_DIR, 'media')

MEDIA_URL = '/media/'
Arghya Saha
  • 5,599
  • 4
  • 26
  • 48
0

Just remove '/' from MEDIA_URL in setting.py like this MEDIA_URL = 'media/'

Deepak0174
  • 47
  • 5
0

I may have faced similar issue. My setup is Gunicorn running behind Nginx. When uploading a file to django media library, the request does not show up in Gunicorn's access log. That means it is stopped by Nginx and a 500 error code was returned. Further search led to this site, https://killtheradio.net/technology/nginx-returns-error-on-file-upload/ , which solved my problem.

Basically, Nginx temporarily saves file body to disk at /var/lib/nginx/client_body. But this folder was not accessible to the Nginx process. A simple chown solved the problem then.

vuamitom
  • 173
  • 2
  • 8