Sandeep Balagopal
Sandeep Balagopal

Reputation: 1983

Nginx 403 for newly created files

My Django app is configured nginx. Media files are served by nginx directly. The issue I have now is that nginx is giving 403 forbidden for the pdf files i uploaded. Pdf files are uploaded to media/file directory. When i do

sudo chown -R www-data:www-data media/file

The file will be loaded. But when i upload another pdf, nginx is again returning 403. I have also tried

sudo chmod g+s media/file

That also did not work. So each time i have to run chown to make the file load.

This is happening only for big files. Files having size less than 1MB is working fine. Permissions are correctly set. But when files having size greater than 1 MB is uploaded the permission is changed. For bigger files only ubuntu group(Default user in aws) is having permission. For small files it is fine, www-data is having the permission.

Upvotes: 2

Views: 234

Answers (1)

Sandeep Balagopal
Sandeep Balagopal

Reputation: 1983

The only solution that worked for me was setting FILE_UPLOAD_PERMISSIONS is Django like below

FILE_UPLOAD_PERMISSIONS = 0o644

There could be a more cleaner method.

Upvotes: 2

Related Questions