I tried setting up nginx with docker on my django project.
I checked the volume exists on docker container. And I do have access to my swagger path, but staticfiles does not load.
What else can I attempt? Thanks…
For example, as settings.py has set the path:
# Static files
STATIC_URL = "/static/"
STATICFILES_DIRS = [
os.path.join(BASE_DIR, "static"),
]
STATIC_ROOT = os.path.join(BASE_DIR, "staticfiles")
and here is nginx/nginx.conf, may see locaiotn in http:
events {
worker_connections 1024;
}
http {
upstream django {
server web:8000;
}
server {
server_name localhost;
access_log off;
listen 80;
location /static/ {
alias /app/staticfiles/;
}
location / {
proxy_pass http://django;
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-Proto $scheme;
}
}
}
And finally, docker-compose script:
version: '3.8'
services:
web:
build: .
command: gunicorn core.wsgi:application --bind 0.0.0.0:8000 --timeout 120 --workers 3
volumes:
- .:/app
- static_volume:/app/staticfiles
ports:
- "8000:8000"
depends_on:
- redis
nginx:
image: nginx:latest
volumes:
- ./nginx/nginx.conf:/etc/nginx/nginx.conf:ro
- static_volume:/app/staticfiles
ports:
- "80:80"
depends_on:
- web
......
volumes:
static_volume:
2
Answers
Case solved. It was type definition issue from nginx.conf.
Let nginx to identify the file types.
Nginx fails to load css files
did you tried to run:
it should work if it’s not docker or nginx issues