I have seen many similar posts but nothing has been able to make the trick for me. Browser throws me this kind of error for all my css files when i load my static. When I collect static it works fine plus when I run findstatic it points me to right directory. SO I am a bit lost on what is going on because my static files seems to be where they should be but nginx cannot find them, altough the path to them is the right one.
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)
from the information I read and the django + nginx documentations, I am not able to spot where I am making a mistake. I have been on it for a few days now and I hope that someone could see what I cannot.
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 made the changes suggested, but it still not working, when I look into nginx error log, it shows the path to static is the following
"/usr/share/nginx/html/staticfiles/
this is wrong because if i go look inside of the html folder, there is only the "welcome to nginx" htlm page. The question is why is nginx searching files over there? I have deleted the default file but the error log keeps pointing even after restarting nginx, the server too.
I think you have a few issues with confusion on the path names you have selected. If you alter your nginx app.conf to:
server {
location /static/ {
root /home/ubuntu/exostocksaas;
}
location / {
include proxy_params;
}
}
Then alter your settings.py file to:
STATIC_URL = '/static/'
# STATICFILES_FINDERS = (
# 'django.contrib.staticfiles.finders.FileSystemFinder',
# )
STATICFILES_DIRS = [
os.path.join(BASE_DIR, 'staticfiles')
]
STATIC_ROOT = os.path.join(BASE_DIR, 'static')
It should start serving your static files correctly. From there you could start making incremental changes to pathnames as you wish but this is the standard config I tend to use for my Django deployments.
STATIC_DIR = os.path.join(BASE_DIR,'static')
add the folder static but at the same path where you use it
put in folder static your staticfiles (css , js ,.... ), and add in html
{% load staticfiles %}