Reputation: 55
I'm aware this has been asked a few others times, but none of those solutions seem to be working for me. This was my first time deploying a Django project, so for reference, I followed this tutorial: https://linuxhint.com/create_django_app_ubuntu/
For that reason, it is entirely possible that something flew over my head completely.
nginx config (I've tried alias instead of root, with and without trailing slash, made sure the static file aren't owned by root, etc.):
upstream django {
server 127.0.0.1:8000;
}
server {
listen 80;
location /static/ {
root /home/bryan/Projects/portfolio;
try_files $uri =404;
}
location / {
try_files $uri @send_to_django;
}
location @send_to_django {
proxy_set_header Host $http_host;
proxy_redirect off;
proxy_pass http://django;
}
}
settings.py:
STATIC_URL = '/static/'
STATIC_ROOT = os.path.join(BASE_DIR, 'static')
STATICFILES_DIRS = (
os.path.join(BASE_DIR, 'static'),
)
Note:
django.contrib.staticfiles
is installedpython manage.py collectstatic
appears to be working{% load static %}
<link rel="stylesheet" type="text/css" href="{% static 'home/css/index.css' %}">
My file structure:
Other than the static files, the site works flawlessly with this setup.
Upvotes: 0
Views: 402
Reputation: 756
STATIC_ROOT = os.path.join(BASE_DIR, 'static')
STATICFILES_DIRS = (
os.path.join(BASE_DIR, 'static'),
)
Settings above may cause static files being collected into /home/bryan/Projects/portfolio/static/static dir
Check static dir permissions
Use "alias" instead of "root" in your nginx conf
Upvotes: 1