Issues with Media and Static File Serving in Django on Production Server
My Django project is already deployed on Linode and it works. Several necessary steps were taken to properly configure the server, the database, Redis, Celery, Stripe, as well as Nginx and Gunicorn.
However, I noticed an issue when I want to upload an image from my Admin Dashboard, for example, to change the photo on my site's homepage. I get a "Server Error (500)." I encounter the same errors when I try to attach a PDF or an image in the quote while submiting it. I want to emphasize that everything works perfectly in local mode.
Secondly, in the User Dashboard, it's impossible to view the invoices of the orders; they get the same error (Server Error (500)), and they cannot view their previous order invoices by clicking on the PDF icon of the invoice.
However, all of this is possible when I am in local mode.
Is there anyone who could help me resolve this?
What would you like to first check in the configurations of my project in local and deployed environments to give me solutions?
File Management (images and PDFs)
a. Configuration of MEDIA in Django
Production Mode:
MEDIA_URL = "/media/"
MEDIA_ROOT = os.path.join(BASE_DIR, "media/")
Nginx configuration for MEDIA_ROOT:
bash
Copier le code
server {
server_name tsalachmt.com www.tsalachmt.com;
location /static/ {
root /home/tsalachmt/tsalachmtdir;
}
location /media/ {
root /home/tsalachmt/tsalachmtdir;
}
}
location / {
….}
}
Local Mode:
MEDIA_URL = "media/"
MEDIA_ROOT = os.path.join(BASE_DIR, "media")
Thank for your help!!!!!!!!