1👍
-
There was a hidden problem of permission. I put the static folder in /var/www/ instead of the root folder. Then I changed ownership to allow nginx to get access to it:
chown -R root:www-data /var/www/static/
-
in nginx configuration the word static shouldn’t be repeated. That is to do this:
location /static/ { root /var/www/; }
instead of this:
location /static/ { root /var/www/static; }
-
I changed the STATIC_ROOT VARIABLE in setting.py as follows:
STATIC_ROOT = "/var/www/static"
Then I restarted nginx and gunicorn service and the problem was solved.
0👍
The CSS works when you do python manage.py runserver
because it knows where to find static files in your code. On the other hand, gunicorn doesn’t know where to look for them.
You need to set STATIC_ROOT
and run python manage.py collectstatic
on your server. You already have nginx set up to serve the files once you collect them to the location that nginx will look for them.
See the official documentation for more details about deploying. Also see the section on configuring static files.