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- I do believe I am referencing the static files correctly in my templates:
{% load static %}
<link rel="stylesheet" type="text/css" href="{% static 'home/css/index.css' %}">
My file structure:
- portfolio (django project root)
- home (django app)
- static (project static files)
- home (static files for home app)
- css
- home (static files for home app)
Other than the static files, the site works flawlessly with this setup.