I've come across several similar posts, but none of the solutions seem to work for me. Every time I load my static files, the browser throws errors like these: When I collect static files, everything works fine. Even running findstatic points me to the correct directory. So I'm confused as to why nginx can't locate them, even though the path is correct.
GET https://www.exostock.net/staticfiles/vendor/font-awesome/css/font-awesome.min.css net::ERR_ABORTED 404 (Not Found)
and
Home:136 GET https://www.exostock.net/staticfiles/img/logo8.png 404 (Not Found)
Despite reading through django and nginx documentation, I can't figure out where I'm going wrong. I've been stuck on this for days and hope someone can spot what I'm missing.
nginx/sites-available/app.conf
server {
server_name exostock.net www.exostock.net;
location / {
include proxy_params;
proxy_pass http://unix:/home/ubuntu/exostocksaas/app.sock;
}
location /static/ {
alias /home/ubuntu/exostocksaas/collected_static/;
}
location ~ \.css {
add_header Content-Type text/css;
}
location ~ \.js {
add_header Content-Type application/x-javascript;
}
}
settings.py in django
STATIC_URL = '/staticfiles/'
# STATICFILES_FINDERS = (
# 'django.contrib.staticfiles.finders.FileSystemFinder',
# )
STATICFILES_DIRS = [
os.path.join(BASE_DIR, 'staticfiles')
]
STATIC_ROOT = os.path.join(BASE_DIR, 'collected_static')
and my html links to statics
<!-- Bootstrap CSS-->
<link href="{% static 'vendor/bootstrap/css/bootstrap.min.css' %}">
<!-- Font Awesome CSS-->
<link href="{% static 'vendor/font-awesome/css/font-awesome.min.css' %}">
<!-- Custom Font Icons CSS-->
<link href="{% static 'css3/font.css' %}">
UPDATE: I tried the suggested changes, but it's still not working. When I check the nginx error log, it shows the static file path as:
"/usr/share/nginx/html/staticfiles/
This is incorrect because if I look inside the html folder, all I see is the default "welcome to nginx" HTML page. Why is nginx searching for files there? I've deleted the default file, yet the error log persists even after restarting the server.