Nginx won't serve my Django static files while gunicorn serves as expected. I have my settings as:
STATIC_URL = '/static/'STATICFILES_DIRS = [BASE_DIR / 'static']STATIC_ROOT = os.path.join(BASE_DIR, 'staticfiles')
while my nginx.conf has:
events {}http { server { listen 80; server_name 127.0.0.1 cloud101.dev www.cloud101.dev; # Correctly point to your static files directory # root /usr/src/app/staticfiles; location /static { root /usr/src/app/staticfiles; } location / { proxy_pass http://127.0.0.1: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; }
the Dockerfile has:
# pull the official base imageFROM python:3.12.2-bullseye...# Install Nginx and dependenciesRUN apt-get install -y nginx# copy projectCOPY . /usr/src/appCOPY website/nginx.conf /etc/nginx/nginx.confEXPOSE 8000RUN python manage.py collectstatic -v 2 --noinputCMD ["gunicorn", "--bind", "0.0.0.0:8000", "website.wsgi:application"]
gunicorn serves alright but the static files are not served although the default server does. What am I missing?