403 forbidden for big media files nginx

June 27, 2017 192 views
Nginx Django

I set up my Django server and it's been operating for a while now. I experienced this really weird bug where certain files (>1MB) get rejected by Nginx. error.log indicated the following as an example:
2017/06/27 01:03:29 [error] 1643#1643: *30 open() "/home/brian/nydkc11/nydkc11/nydkcd11/media/image_main/dtc1.jpg" failed (13: Permission denied), client:, server: nydkc11.org, request: "GET /media/image_main/dtc1.jpg HTTP/1.1", host: "nydkc11.org", referrer: "http://nydkc11.org/admin/blog/image/7/change/"

The weirdest thing is that Nginx serves static files on the <1MB just fine, and the problematic files serve perfectly on Django's development server. Could someone tell me what's going on and how I can fix the problem?

Note: I put client_max_body_size 100M; to fix an Error 413 that emerged when I originally tried uploading the large file.

My droplet runs on Ubuntu 16.04, and utilizes Django, Gunicorn, and Nginx. I followed this tutorial to set it up:

2 Answers

Like it says, "Permission denied". Fix your chmod/chown so nginx can access the file.

Hi @leebr1

You need to make sure that everything within /home/brian is owned by brian:brian and then the Gunicorn and Nginx should run with those permissions too.
If they run with the default www-data:www-data permissions, then everything that has to do with your website, has to be owned by that.

  • how would I go about checking up those permissions? In addition, if the permissions do come out wrong, how may I properly set those permissions? I know for sure nginx runs with the user www-data since it's set as such in my nginx.conf.

    • Go to /home/brian and run ls -l to list everything in that directory and it's owner:group. And then go down through the hierarchy.

Have another answer? Share your knowledge.