Im getting crazy and very frustrated about deploying static files of my django app since 1 month- all things are ok except static and media files which cannot be served by the web server ( i tried apache and nginx)
Firstable- in dev mode my app is ok and the static file are correctly loaded.
switching to prod Env - all my attempts to get over the issue are unsuccessful.
im using
- ubuntu Ubuntu 22.04.4 LTS
- Django==3.2.9
- gunicorn (version 22.0.0) as app server
- nginx 1.18.0 as reverse proxy -
i set up the setting.py and nginx conf with the correct path to static folder as following
STATICFILES_FINDERS = [
'django.contrib.staticfiles.finders.FileSystemFinder',
'django.contrib.staticfiles.finders.AppDirectoriesFinder',
]
STATICFILES_DIRS = []
STATIC_URL = '/static/'
STATIC_ROOT = '/var/www/html/bweb/staticfiles'
MEDIA_URL = '/media/'
MEDIA_ROOT = '/var/www/html/bweb/media'
LOCALE_PATHS = (
os.path.join(BASE_DIR, 'locale'),
os.path.join(BASE_DIR, 'core', 'locale'),
----------------------
--------------------------
nginx
location /static/ {
alias /var/www/html/bweb/staticfiles/;
access_log /var/log/nginx/static_access.log;
error_log /var/log/nginx/static_error.log;
expires 30d;
}
location /media/ {
alias /var/www/html/bweb/media/;
access_log off;
expires 30d;
}
------------------------
- i installed & set gunicorn to serv the app
- i run the collectstatic command witch copied the files into the path i mentioned in settings.py (several times - django detects each time the presence of the files what means that the conf is ok)
-im using debug = false in prod mod
=>> whats happening
my app is running in prod mode (gunicorn seems to do the job) but i'm getting 404 errors for all my static files -
==> Here what i tried
- i gave permissions to data-www user over the folder and all its components which are actually present inside with the folder with the correct permissions
- i run the server in a separate port which is unused in the system - with allowed permissions in firewall
-i cleared the cache and tried out several browsers
- i tried to put manually a test file in the folder and try to access with curl -
the files still dont want to be served even the test file.
Log files aren't showing any significant error .
all those attempts were tested with apache web server but i encounter the same issue
-------
Any one have faced such issue? ubuntu problem ? Django version issue?
I'll be very thankful for help