403 forbidden for big media files nginx

Posted June 27, 2017 15k views

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:, request: "GET /media/image_main/dtc1.jpg HTTP/1.1", host: "", referrer: ""

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:

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Submit an Answer
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.