For some unexpected reason, my nginx server responses static files (like .css and .js) for too long time. For example, there are some connected scripts and stylesheets on page with filesize less than 10kb. Chrome devtools timeline profiling shows, that those files are downloaded for about 15+ seconds (see screenshot below).
Timeline profiling in Chrome DevTools
What can be a reason for responsing static files such a long time?
Important update. I noticed, that it happens only on html pages. If to open any js or css file singulary, it loads fastly, as it's actually expected.
I use nginx+apache bundle on my server, and nginx is responsible for all the static files, such as js, css, images and etc..
Thx in advance.
-
Does this happen in other browsers as well?michip96– michip962017年01月11日 20:48:13 +00:00Commented Jan 11, 2017 at 20:48
-
Yes, in Chrome, Safari, IE (including Edge) and FireFox (latest versions).impulsgraw– impulsgraw2017年01月11日 21:24:48 +00:00Commented Jan 11, 2017 at 21:24
-
Does this error occurs every time you connect to the server or just at the first try? You could have a problem with DNS lookups. (serverfault.com/a/385161) Are you sure the files are loading fastly when you open them directly? Maybe your browser cached them..michip96– michip962017年01月11日 22:35:27 +00:00Commented Jan 11, 2017 at 22:35
-
Yes, I'm sure. I tried to open them with flushed cache (and also directly from other computers on which I have never opened my website before). They are loading in less then 500ms.impulsgraw– impulsgraw2017年01月11日 23:17:32 +00:00Commented Jan 11, 2017 at 23:17
1 Answer 1
My problem was caused by DDoS-protection (ngx_http_limit_req_module), which was configured incorrectly. I have inadvertently copy-pasted nginx config somewhere from internet onto my server (so, everything worked fine, excepting the page loading time). Thx god I've got a point to check nginx error log, in which were warnings like
2017年01月12日 04:14:33 [warn] 21347#21347: *120 delaying request, excess: 0.975, by zone "my_host", client: my_ip_address, server: my_host, request: "GET JS_OR_CSS_SCRIPT_URI HTTP/1.1", host: "my_host", referrer: "page_url_which_was_requesting_js_or_css"
So, googling helped to configure limit_req_zone and limit_req correctly:
http {
limit_req_zone $host zone=hostreqlimit:20m rate=1500r/m;
...
server {
...
limit_req zone=hostreqlimit burst=2500 nodelay;
...
}
}
Sorry for a silly question c:
Comments
Explore related questions
See similar questions with these tags.