Parece que a configuração do docker-compose não estava correta. A razão pela qual o nginx jogou esses 404s foi porque não tinha acesso a /usr/src/app/defsec-exam-app/static
.
Aqui está a configuração correta do docker-compose -:
# Nginx
nginx:
build: ./nginx
volumes_from:
- django
links:
- django
ports:
- "80:80"
# This defines a service for the Django app
# Will include the Angular frontend
django:
build: .
volumes:
- .:/root
- /usr/src/app
expose:
- "8000"
links:
- postgres
# This defines a service for the Postgres database
postgres:
image: postgres:latest
volumes_from
obtém os volumes do serviço django. E eu expus usr/src/app
como um volume. Isso parece fazer o truque. Estou aberto a sugestões, se houver!
Além disso, aqui está a nova configuração do nginx -:
worker_processes 1;
events {
worker_connections 1024;
}
http {
server {
listen 80;
server_name example.org;
access_log /dev/stdout;
error_log /dev/stdout info;
location /static/ {
alias /usr/src/app/defsec-exam-app/static;
}
location /static/javascripts/ {
default_type text/javascript;
alias /usr/src/app/defsec-exam-app/static/javascripts/;
}
location /static/stylesheets/ {
default_type text/css;
alias /usr/src/app/defsec-exam-app/static/stylesheets/;
}
location /static/bower_components/ {
types {
text/css css;
text/javascript js;
}
alias /usr/src/app/defsec-exam-app/static/bower_components/;
}
location /static/partials/ {
types {
text/html html;
}
alias /usr/src/app/defsec-exam-app/static/partials/;
}
location /static/admin/ {
alias /usr/src/app/defsec-exam-app/static/admin/;
}
location /static/admin/css {
default_type text/css;
alias /usr/src/app/defsec-exam-app/static/admin/css;
}
location /static/admin/js {
default_type text/javascript;
alias /usr/src/app/defsec-exam-app/static/admin/js;
}
location /static/admin/img {
types {
image/png png;
image/jpeg jpg;
}
alias /usr/src/app/defsec-exam-app/static/admin/img;
}
location / {
proxy_pass http://django: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;
proxy_set_header X-Forwarded-Host $server_name;
}
}
}
Nota: Eu tive que adicionar o django admin css / js / img ao repositório docker / deployment separadamente, para que o django admin funcionasse corretamente. (Um simples comando ADD no django Dockerfile faz o truque)