Static files coming sometimes broken
See original GitHub issueHi, i have my Django application and i use nginx to proxy my static files only! and reason i use nginx-proxy because i can use it host multiple sites at my vps without much of hassle. At my website, that is https://bigtoolstation.com/ sometimes suddenly it shows 404 and if we see in console. we will see:
because its coming 404 😦. it happens mostly and is randomly on all browsers. Here is my nginx configuration file.
upstream web_server {
server web;
}
server {
listen 80;
server_name 0.0.0.0;
charset utf-8;
client_max_body_size 1G;
location /static/ {
alias /app/static/;
expires 365d;
add_header Cache-Control public;
tcp_nodelay off;
open_file_cache max=3000 inactive=120s;
open_file_cache_valid 45s;
open_file_cache_min_uses 2;
open_file_cache_errors off;
access_log off;
}
location / {
proxy_pass http://web_server;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_buffers 16 32k;
proxy_buffer_size 64k;
proxy_busy_buffers_size 128k;
proxy_cache_bypass $http_pragma $http_authorization;
proxy_connect_timeout 1d;
proxy_hide_header X-Powered-By;
proxy_ignore_headers Cache-Control Expires;
proxy_next_upstream error timeout invalid_header http_500 http_502 http_503 http_504 http_404;
proxy_no_cache $http_pragma $http_authorization;
proxy_pass_header Set-Cookie;
proxy_read_timeout 10d;
proxy_redirect off;
proxy_send_timeout 10d;
proxy_temp_file_write_size 64k;
proxy_set_header Accept-Encoding '';
proxy_set_header Cookie $http_cookie;
proxy_set_header Host $host;
proxy_set_header Proxy '';
proxy_set_header Referer $http_referer;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Host $host;
proxy_set_header X-Forwarded-Server $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header X-Original-Request $request_uri;
}
}
if there’s something wrong my side or need more information, kindly let me know. Thank you.
Issue Analytics
- State:
- Created 3 years ago
- Comments:6
Top Results From Across the Web
Django static files are broken - Stack Overflow
I'm trying to add a background picture to the hero section in Django, But whenever I open that URL: http://127.0.0.1:8000/static/img/bg.png ...
Read more >Improve Load Times for APEX Static Files
In this post, I'll discuss several best practices to improve load times for your JavaScript, CSS, Image, and other static files.
Read more >Errors and broken links | WordPress.org
Errors and broken links · 1. Go to All in One SEO > XML Sitemap and enable the Dynamically Generate Sitemap setting. ·...
Read more >Pitfalls and Common Mistakes | NGINX
The try_files directive exists for an amazing reason: It tries files in a specific order. NGINX can first try to serve the static...
Read more >Magento 2 CSS and JavaScript not loading from correct folder
Now we are going to verify Composer installation, Deploy static content, clear / flush Magento cache, and reindex the Magento 2 blocks. To...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Thank you for the suggested help. However that is not going to work for me. But i’m sure this will help somebody else in future. if this issue is not resolved.
Hmm, that all looks right to me. I am not sure why this happens, especially the instability with 404s. The only thing I can imagine that different
nginx
workers pick up the request and one of them is configured incorrectly. I don’t know why that would be the case though.For static file serving with django, I switched to uwsgi as opposed to gunicorn. Reason being that it can serve both Django wsgi requests and static files. That way I never have to worry about running nested nginx instances (one for
nginx-proxy
, one for the django app). In your case the config for uwsgi would be something like:Depending on how much you rely on gunicorn uwsgi might or might not be an option.