How to serve media files?

I have an Django application and I trying deploy this, but I have problem, in this moment I can see my media files because I add media and static into (as must be done in development), but I trying change to production mode and I use nginx, but I don’t understand how to server my media files with nginx, I have configured nginx this way

server {
    listen 80;
    server_name ip_server

    location = /favicon.ico { access_log off; log_not_found off; }
    location /static/ {
        root /home/ubuntu/tracker-web/trackerServer;
    location /media/ {
        alias /home/ubuntu/tracker-web/trackerServer/media/;
    location / {
        include proxy_params;
        proxy_pass http://unix:/home/ubuntu/tracker-web/trackerServer/trackerServer.sock;

Before I only use /static/ and all works fine, but I don’t understand how to use the same way my media folder to serve files, I want to clarify that I use as an angular 2 interface , so I do not use Django templates, and also use gunicorn.

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.

Sorry to see that your question hasn’t received an answer yet. It’s unclear exactly what problem you are facing without more information. Unfortunately, after this much time, it is unlikely an answer for this specific question will be provided.

For people still landing here via search, the path used for /media/ in the Nginx configuration should match what the project’s file uses for MEDIA_ROOT. You might also want to check out this tutorial on getting up and running with Django and Nginx: