3

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.

asked Jan 11, 2017 at 20:42
4
  • Does this happen in other browsers as well? Commented Jan 11, 2017 at 20:48
  • Yes, in Chrome, Safari, IE (including Edge) and FireFox (latest versions). Commented 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.. Commented 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. Commented Jan 11, 2017 at 23:17

1 Answer 1

3

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:

answered Jan 12, 2017 at 1:33
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.