Nginx not serving images in a Django blog

(Immanuel) #1

Hello everyone, I recently deployed a blog. Everything seems to be doing fine except for images. Images for posts are not being served. I once deployed a blog before and had no issue like this. The nginx-access.log file says "GET /media/posts/2019/02/06/76bKaN.jpg HTTP/1.1" 404 102 "". What could be wrong?

NB: I deployed on DigitalOcean, serving static files with Nginx.

(Vitor Freitas) #2

It might be the nginx conf missing the instructions of where to find the media files like this:

server {

    # other conf...

    location /static/ {
        alias /opt/yourapp/static/;

    location /media/ {
        alias /opt/yourapp/media/;

Just make sure to change /opt/yourapp/media/ to the actual path of where to find your media files

(Vitor Freitas) #3

Also here is an example of a complete nginx conf file:

(Immanuel) #4

Hey @Vitor, this absolutely worked! I forgot to add the location to my media files. Thank you very much!