Question

Upload media files django nginx

I’m trying to upload media files on the server but can’t figure out how to do it. I have no problem accessing my media files, but can’t upload any.

Here is what I’ve tried:

server {
    listen 80;
    server_name ****;

    location = /favicon.ico { access_log off; log_not_found off; }
    location /static/ {
        root /home/joseph/hacka;
    }
    location /media/ {
        root /home/joseph/hacka;
    }
    location / {
        include proxy_params;
        proxy_pass http://unix:/run/gunicorn.sock;
    }
}

In my settings.py, I have :

MEDIA_URL = '/media/'
MEDIA_ROOT = os.path.join(BASE_DIR, 'media')

Please help me if you know the answer to my problem.

Show comments

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.

I don’t know if this answer will work after this much time. But it will be helpful for coming developers. By default nginx has limit of 1MB file upload. So, you have to change it according to your requirement… Steps:

  1. sudo systemctl stop nginx

  2. Open the nginx.conf file (path on linux /etc/nginx/nginx.conf)

  3. Add this line into your nginx.conf file client_max_body_size 20M; 20M means 20MB… 100M means 100MB…

  4. save file and start the nginx ‘sudo systemctl start nginx’