1

For some reason, my CSS, JS, and Font-Awesome static assets are recognized and serving properly, but my img static files are showing 404 errors in the Nginx Docker container logs.

Everything works fine when I build these containers locally, but as soon as I build on Digital Ocean, the img files start to throw 404 errors with Nginx.

I've been tooling around for a few days with no luck, any help would be GREATLY appreciated.

Here are my Nginx settings:

server { listen 80; server_name 104.236.29.80; access_log /dev/stdout; error_log /dev/stdout info; location /static/ { alias /usr/src/app/personal/static/; } location / { proxy_pass http://web:8000; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; } } 


Here's the Dockerfile for my Nginx build:

FROM tutum/nginx RUN rm /etc/nginx/sites-enabled/default ADD sites-enabled/ /etc/nginx/sites-enabled 


My Docker-compose file looks a bit like this:

web: restart: always build: ./web expose: - 8000 links: - postgres:postgres volumes: - ./web:/usr/src/app env_file: - .env command: /usr/local/bin/gunicorn etandme.wsgi:application -w 2 -b :8000 nginx: restart: always build: ./nginx ports: - 80:80 volumes_from: - web links: - web:web 


Error logs look a bit like this:

"GET /static/js/creative.js HTTP/1.1" 200 1860 "http://104.236.29.80/" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_5) AppleWebKit/537.36 (KHTML, like Gecko) [error] 7#0: *7 open() "/usr/src/app/personal/static/img/Monkeypod.jpg" failed (2: No such file or directory), client: 98.151.113.208, server: 159.203.166.130, request: "GET /static/img/Monkeypod.jpg HTTP/1.1", host: "104.236.29.80", referrer: "http://104.236.29.80/" 


I can confirm that I've run 'collectstatic' in the web container from the command line, and the terminal confirms the img files have been copied to the static root (/usr/src/app/personal/static/).

I'm completely lost as to why only a portion of the static files would be serving, especially since they're all located in the same directory and referenced in the Django backend with the same syntax.

Thank you kindly for your time and attention!

1 Answer 1

0

Found the issue!

For some reason, when I run collectstatic on the production server, (Digital Ocean Docker droplet), the .jpg files are copied into the static root directory with a .JPG extension.

After making some changes to my Django templates and swapping .jpg with .JPG in the template tags, everything serves properly now.

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.