How to serve media files?

August 16, 2017 302 views
Nginx Django Ubuntu

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 urls.py (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.

Be the first one to answer this question.