Django doesn't find CSS files for admin pages using uWSGI

Official deployment docs (independently by the WSGI server) do not cover serving static files (that is generally managed by the webserver). The right docs are here:

https://docs.djangoproject.com/en/dev/howto/static-files/deployment/

eventually serving static files is pretty easy with uWSGI:

http://uwsgi-docs.readthedocs.org/en/latest/StaticFiles.html

but if you can do it in nginx it is better


I have the same problem. My nginx server on Centos 7.6 can't access to static folder in path /home/user/app/mysyte/static/. In /var/log/nginx/error.log same error

open() "/home/user/app/mysyte/static/*.css" failed (13: Permission denied)

For solving and understanding this problem :=*

  1. run command getenforce
  2. if enforcing - cat /var/log/audit/audit.log | grep nginx

for me string with errrors looks like

type=AVC msg=audit(1558033633.723:201): avc:  denied  { read } for  pid=7758 comm="nginx" name="responsive.css" dev="dm-0" ino=17312394 scontext=system_u:system_r:httpd_t:s0 tcontext=unconfined_u:object_r:user_home_t:s0 tclass=file permissive=0
type=SYSCALL msg=audit(1558033633.723:201): arch=c000003e syscall=2 success=no exit=-13 a0=564f710dd55d a1=800 a2=0 a3=68632f656d6f682f items=0 ppid=7757 pid=7758 auid=4294967295 uid=998 gid=996 euid=998 suid=998 fsuid=998 egid=996 sgid=996 fsgid=996 tty=(none) ses=4294967295 comm="nginx" exe="/usr/sbin/nginx" subj=system_u:system_r:httpd_t:s0 key=(null)

copy id of audit msg 1558033633.723:201

  1. run command grep yours_audit_id /var/log/audit/audit.log | audit2why

output for me

[root@uwsgi ~]# grep 1558034479.384:221 /var/log/audit/audit.log | audit2why
type=AVC msg=audit(1558034479.384:221): avc:  denied  { read } for  pid=7758 comm="nginx" name="responsive.css" dev="dm-0" ino=17312394 scontext=system_u:system_r:httpd_t:s0 tcontext=unconfined_u:object_r:user_home_t:s0 tclass=file permissive=0

        Was caused by:
        The boolean httpd_read_user_content was set incorrectly.
        Description:
        Allow httpd to read user content

        Allow access by executing:
        # setsebool -P httpd_read_user_content 1

So as you can see answer here setsebool -P httpd_read_user_content 1 when you run this command you see your static content