Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

562
Visualizações
Nginx + Django errors when loading ccs files in production

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.

over 4 years ago · Santiago Trujillo
2 Respostas
Responde à pergunta

0

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.

over 4 years ago · Santiago Trujillo Relatório

0

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 %}
over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda