Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

334
Views
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 answers
Answer question

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 Report

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!