Search code examples
pythondjangonginxwebservergunicorn

Static files are not found (gunicorn)


I know this question was already asked frequently. But the supposed solutions seem not to help me.

Here is my Nginx definition for the static files

    location /static/ {
        alias /data/atsi_webapp/ATSi_WebApp/static;
    }

Here my Django settings

BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
STATIC_ROOT = os.path.join(BASE_DIR, 'staticfiles')
STATIC_URL = '/static/'
STATICFILES_DIRS = (
    os.path.join(BASE_DIR, 'static'),
)

I did run already

python manage.py collectstatic

However, I get

Not Found: /static/js/xxxx.js


Solution

  • I think your nginx declaration causes the issue.

    Could you please try this:

    location /static/ {
        # static files
        autoindex on;
        autoindex_exact_size off;
        # /data/atsi_webapp/ATSi_WebApp <-- may be in your case
        root /exact/path/to/project/folder;
    }
    

    Instead of this:

    location /static/ {
        alias /data/atsi_webapp/ATSi_WebApp/static;
    }