issue with static files deployement in Prod envirenment (new issu)

110 views
Skip to first unread message

Abulbanat Mosta (Abulila)

unread,
Aug 25, 2024, 10:17:13 AMAug 25
to Django users
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

ASAMOAH EMMANUEL

unread,
Aug 25, 2024, 10:39:54 AMAug 25
to django...@googlegroups.com
I understand how frustrating this can be. I also faced this same issue for months and this was how I solved it.

  sudo usermod -a -G your_user www-data

  sudo chown -R :www-data /path/to/your/static/folder


Let me know if it is still not solved and I will help you.
Swimmingly,
Simple_genius

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/450049e4-2fff-4700-a4da-286826bf1d95n%40googlegroups.com.


--
I don't stop when I'm tired, I only stop when the job is done.

Abulbanat Mosta (Abulila)

unread,
Aug 25, 2024, 1:27:56 PMAug 25
to Django users
Thank you a lot  EMMANUEL  for this hint- i'll try and return back to you with insghts

Abulbanat Mosta (Abulila)

unread,
Aug 31, 2024, 2:15:48 PMAug 31
to Django users
Hi Emmanuel
i tried the solution you provided , but sadly it doesn't work too- i add the my user and www.data user to the same group (i tried this with sudo in venv and outside venv) igave the permissions required to deal with the files - but no way. its still not working- . i am sure that's a permissions issue but what a kinf of issue is ? any other suggestion

ASAMOAH EMMANUEL

unread,
Sep 1, 2024, 5:57:12 PMSep 1
to django...@googlegroups.com
Hi,
Sorry to hear this.
Perhaps we can have a private email conversation where we debug this together.
I need to look at your NGinX configurations, static directory, configuration of static assets in settings file etc.
Let me know if you prefer this option.
Swimmingly,
Simple_genius

Reply all
Reply to author
Forward
0 new messages