[Answered ]-403 error for new files posted through django admin

2👍

TL;DR:

  • FILE_UPLOAD_PERMISSIONS = 0o644 in settings.py
  • in bash shell: find /path/to/MEDIA_ROOT -type d -exec chmod go+rx {} +

The explanation

The files are created with permissions that are too restrictive, so the user Nginx runs as, cannot read them. To fix this you need to make sure Nginx can read the files and can get to the files.

The goal

First you need FILE_UPLOAD_PERMISSIONS to allow reading by the Nginx user. Second, MEDIA_ROOT and all subdirectories must be readable by Nginx and writeable by Gunicorn.

How to

You must ensure the directories are world readable (and executable) or the group for the directories must be a group that the Nginx process belongs to and they must be at least group readable (and executable).

As a side note, you said you’ve used chmod and chown before, so I assumed you were familiar with the terminology used. Since you’re not, I highly recommend fully reading the linked tutorial, so you understand what the commands you used can do and can screw up.

Leave a comment