[Answered ]-Nginx responds 404 not found on Django media URL in preprod, dev ok

1👍

Django does not serve static- and media files with runserver, you will need WhiteNoise for that. See http://whitenoise.evans.io/en/stable/
Whitenoise however is not suitable for serving user-uploaded media files. See http://whitenoise.evans.io/en/stable/django.html#serving-media-files

(Optionally, skip whitenoise, and host static/media files through NGINX.)

You really shouldn’t be hosting your server with py manage.py runserver. This is not secure. See Why not use "runserver" for production at Django? and https://docs.djangoproject.com/en/dev/ref/django-admin/#runserver

Use something like Gunicorn instead.

See https://docs.djangoproject.com/en/4.1/howto/deployment/wsgi/gunicorn/

(Or waitress, the windows alternative)

https://pypi.org/project/django-waitress/

To host static/media files with nginx, paste this into your nginx conf:

    location /media  {
        alias /PATH/TO/DIRECTORY; #Absolute path.
    }

And in your settings.py, set the media root to that same directory.

Leave a comment