M
M
Mike2019-06-02 17:56:24
Django
Mike, 2019-06-02 17:56:24

Why can't I mount django/nginx static files?

Made a simple demo_blog. Unable to distribute static files. In settings.py
I have:

STATIC_URL = '/static/'
STATIC_ROOT = '/root/demoblog/static/'

STATICFILES_DIRS = (
    os.path.join(BASE_DIR, 'static'),
)

python manage.py collectstatic
innginx
server {
    listen 80;
    server_name ip_of_my__blog; 
    access_log  /var/log/nginx/example.log;

    location /static/ {
        root /root/demoblog/;
        expires 30d;
    }

    location / {
        proxy_pass http://127.0.0.1:8000; 
        proxy_set_header Host $server_name;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    }
  }

My demo_blog is at /root/demoblog/ on DigitalOcean
I reload nginx sudo service nginx restart
Then I run demo_blog gunicorn blog.wsgi:application
It works but no static is served. What's the matter, what's wrong?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergey Gornostaev, 2019-06-02
@google_online

Nginx does not have access to /root, and the django project does not belong in this directory.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question