static files on nginx wont work


I’m trying to deploy my website and I used an nginx server with gunicorn. The server works as expected but the static files wont work, I guess I messed something up in my

STATIC_URL = '/static/'

STATIC_ROOT = "/root/static"

I already moved my static files with collectstatic to my new directory on my server and they are in there but it doesnt work on the website.

this is in my sites-available from NGINX

location /static/ {
	root /root/static;

I set something up wrong but I dont know where the error is.

Check first to ensure that nginx has permissions to those files. (Likely not. Note that while you might start nginx as root, the nginx process will downgrade itself to a non-root account by default. You definitely don’t want nginx itself running as root.)

In the common case, you want to deploy your static files to a directory already owned / accessible to nginx, which usually means something under /var/www. You almost certainly don’t want to expose /root to the outside world under any circumstances.

See: Pitfalls and Common Mistakes | NGINX

Also see:

and note the distinction between what’s served with root vs alias.

so this is my now:

STATIC_URL = '/static/'
STATIC_ROOT = "/var/www/"

and this is my sites-avalable:

location /static/ {
	root /var/www/;

and after collectstatic command the files were moved to the var directory but on my site there still isnt any static content.

How can I check that nginx has the permission that it needs? What should I do that it runs correctly?

I’m thinking in this case it’s the “root” vs “alias” situation. Change the directive from root to alias.