Question

403 forbidden for big media files nginx

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: 108.29.217.25, 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: https://www.digitalocean.com/community/tutorials/how-to-set-up-django-with-postgres-nginx-and-gunicorn-on-ubuntu-16-04


Submit an answer

This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

Sign In or Sign Up to Answer

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.

Want to learn more? Join the DigitalOcean Community!

Join our DigitalOcean community of over a million developers for free! Get help and share knowledge in Q&A, subscribe to topics of interest, and get courses and tools that will help you grow as a developer and scale your project or business.

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.

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