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

332
Visualizações
nginx looking for staticfiles in the wrong place

my Django deployment with ec2, nginx and gunicorn went well beside that my staticfiles are not loading, browser show a 404 error. And this is because nginx looks in a completely different place than statics. At this point I have tried a lot of configurations and nothing does the trick. I am wondering if a pair of fresh eyes can spot a mistake here that I do not.

/sites-enabled/django.conf:

server {
    server_name  site.net www.site.net;

    location /static/ {
        autoindex on;
        alias /home/ubuntu/saas/static/;
}

    location / {
        include proxy_params;
        proxy_pass http://unix:/home/ubuntu/saas/app.sock;
}

    location ~ \.css {
        add_header  Content-Type    text/css;
}
    location ~ \.js {
        add_header  Content-Type    application/x-javascript;
}

    listen 443 ssl; # managed by Certbot
    ssl_certificate /etc/letsencrypt/live/site.net/fullchain.pem; # managed by Certbot
    ssl_certificate_key /etc/letsencrypt/live/site.net/privkey.pem; # managed by Certbot
    include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
    ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot


}



server {
    if ($host = www.site.net) {
        return 301 https://$host$request_uri;
    } # managed by Certbot


    if ($host = site.net) {
        return 301 https://$host$request_uri;
    } # managed by Certbot



    listen 80;
    server_name  site.net www.site.net;
    return 404; # managed by Certbot
}

and my django settings.py look like this and collectstatics works fine.

STATIC_URL = '/static/'

STATICFILES_DIRS = [
    os.path.join(BASE_DIR, 'staticfiles')
]

STATIC_ROOT = os.path.join(BASE_DIR, 'static')

I have deleted the default file but it stills seems that nginx looks for the staticfiles in the wrong place according to this error.log:

2020/05/01 19:57:45 [error] 3502#3502: *6 open() "/usr/share/nginx/html/static/css/custom.css" failed (2: No such file or directory), client: 86.221.78.105, server: site.net, request: "GET /static/cs$

I have rebooted the server, reload nginx, nothing seems to work out. Would someone has an idea of what I could try at that point?

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

0

There's usually a default.conf file that gets installed with nginx when you install with yum or apt. It will either be in /etc/nginx/conf.d/default.conf or /etc/nginx/sites-enabled/default.conf. Delete that file and reload nginx with sudo systemctl reload nginx, and you should be good to go absent there being another configuration file on your server that you don't know about.

over 4 years ago · Santiago Trujillo Relatório

0

Here is what I did to resolve the problem. Getting rid of the default index.html in /usr/share/nginx/html/ and running the conf script as:

server {
    server_name  site.net www.site.net;

    listen 443 ssl; # managed by Certbot
    ssl_certificate /etc/letsencrypt/live/site.net/fullchain.pem; # managed by Certbot
    ssl_certificate_key /etc/letsencrypt/live/site.net/privkey.pem; # managed by Certbot
    include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
    ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot



    location /static/ {
        autoindex on;
        alias /home/ubuntu/saas/static/;
}

    location / {
        include proxy_params;
        proxy_pass http://unix:/home/ubuntu/saas/app.sock;
}

}



server {
    if ($host = www.site.net) {
        return 301 https://$host$request_uri;
    } # managed by Certbot


    if ($host = site.net) {
        return 301 https://$host$request_uri;
    } # managed by Certbot



    listen 80;
    server_name  site.net www.site.net;
    return 404; # managed by Certbot
}

Although this seems to be a workaround it makes the trick
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