Answer the question
In order to leave comments, you need to log in
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
nginx
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;
}
}
sudo service nginx restart
gunicorn blog.wsgi:application
Answer the question
In order to leave comments, you need to log in
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 questionAsk a Question
731 491 924 answers to any question