Nginx doesnt serve django media files
Hi there. I deploy my django apps nginx. Before i connect domain to my app everything works fine. But now media files doesn't serve by nginx. Can any one help me please?
Ps: Media folder has www-data ownership.
server {
listen 80;
server_name IP;
location = /favicon.ico { access_log off; log_not_found off; }
location /static/ {
root /home/username/djangoapp;
}
location / {
include proxy_params;
proxy_pass http://unix:/home/username/djangoapp/djangoapp.sock;
}
}
1 Reply
rdaniels
Linode Staff
hey @ibragim! Thanks for passing along that output. Taking a look at the Nginx configuration block on Django's webpage, it looks like you might need to check your configuration.
server {
listen 80;
listen [::]:80;
server_name $DOMAIN www.$DOMAIN;
root /var/www/$DOMAIN;
location / {
proxy_pass http://localhost:8000;
proxy_set_header Host $http_host;
proxy_redirect off;
proxy_set_header X-Forwarded-For $remote_addr;
proxy_set_header X-Forwarded-Proto $scheme;
client_max_body_size 20m;
}
location /static/ {
alias /var/cache/$DJANGO_PROJECT/static/;
}
}
You'll also want to make sure that you reload the Nginx service after making the configuration changes.
sudo service nginx reload
I suggest reviewing the website linked above for additional setup.
Hope this helps!