Hello everyone,
Opening a new topic because could not find one related to a deployment on production for the same case.
I’ve deployed an app running on Ubuntu 22.04 with Gunicorn and NGINX. Everything works perfectly, even the static files. Already collected static and debug is set to False.
The problem is that my app has options to upload media files like profile pictures and logos. However, when I upload a new one it will not be displayed on the pages where it is supposed to be.
The models that have these ImageField are using the usual upload_to=“my_app/media_folder/” and on my DB I can see the file was saved on a path at https://mydomain.com/media/app_name/image.png
If I check the HTML on the browser, on the element I see the same path. On my actual HTML template code I load the image using {{ object.image.url }} which on development works fine. And if I open the link on the browser I get redirected to my 404.html template.
So, I am wondering where the issue is and what I need to change for production. If it is related to something I need to add to nginx, to settings.py or change where my images get uploaded for production.
I’m not sure what info should I share but here is my settings.py config for static files and media and nginx config:
settings.py
STATIC_URL = "static/"
STATIC_ROOT = os.path.join(BASE_DIR, 'static/')
# Media files
MEDIA_URL = "/media/"
MEDIA_ROOT = Path.joinpath(BASE_DIR, "media")
nginx conf
server {
server_name my_site.com www.my_site.com;
location = /favicon.ico { access_log off; log_not_found off; }
location /static/ {
root /var/www/my_project;
}
location / {
include proxy_params;
proxy_pass http://unix:/run/gunicorn.sock;
}
}
Any guidance will be appreciated.
Thanks!