我有一种情况,当我第一次打开页面时,一切都运行得很快,如果我在一切正常后重新加载页面,如果我重新加载页面第三次浏览器stalles请求大约25秒。有时更多,有时更少。有时它是root的请求,有时是一些静态文件。如果我等待一段时间再刷新,一切都会快速打开,直到第2或第3次刷新网页。
这可能是什么?如果我使用Nginx但是使用Node提供静态文件,我不会遇到这种问题吗?
daemon off;
worker_processes <%= ENV['NGINX_WORKERS'] || 4 %>;
worker_rlimit_nofile 10000;
events {
use epoll;
accept_mutex on;
multi_accept on;
worker_connections 1024;
}
error_log logs/nginx/error.log;
http {
charset utf-8;
include mime.types;
default_type application/octet-stream;
access_log off;
log_format l2met 'measure#nginx.service=$request_time request_id=$http_x_request_id';
access_log logs/nginx/access.log l2met;
sendfile on;
tcp_nopush on;
tcp_nodelay on;
types_hash_max_size 2048;
open_file_cache max=1000 inactive=20s;
open_file_cache_valid 30s;
open_file_cache_min_uses 2;
open_file_cache_errors on;
limit_conn_zone $binary_remote_addr zone=conn_limit_per_ip:10m;
limit_req_zone $binary_remote_addr zone=req_limit_per_ip:10m rate=5r/s;
client_body_buffer_size 16k;
client_header_buffer_size 1k;
client_max_body_size 8m;
large_client_header_buffers 2 1k;
# # - Configure Timeouts
reset_timedout_connection on;
client_body_timeout 12;
client_header_timeout 12;
keepalive_timeout 15;
keepalive_requests 100;
send_timeout 10;
server_tokens off;
# # - Dynamic gzip compression
gzip on;
gzip_http_version 1.1;
gzip_disable "msie6";
gzip_vary on;
gzip_min_length 20;
gzip_buffers 4 16k;
gzip_comp_level 4;
gzip_proxied any;
# Turn on gzip for all content types that should benefit from it.
gzip_types application/ecmascript;
gzip_types application/javascript;
gzip_types application/json;
gzip_types application/pdf;
gzip_types application/postscript;
gzip_types application/x-javascript;
gzip_types image/svg+xml;
gzip_types text/css;
gzip_types text/csv;
gzip_types text/javascript;
gzip_types text/plain;
gzip_types text/xml;
gzip_types text/json;
# proxying requests to other servers
upstream nodebeats {
server unix:/tmp/nginx.socket fail_timeout=0;
}
server {
listen <%= ENV['PORT'] %>;
server_name _;
root "/app/";
limit_conn conn_limit_per_ip 5;
limit_req zone=req_limit_per_ip burst=10 nodelay;
location ~* \.(js|css|jpg|png|ico|json|xml|svg)$ {
root "/app/src/dist/";
add_header Pragma public;
add_header Cache-Control public;
expires 1y;
gzip_static on;
gzip off;
log_not_found off;
access_log off;
}
location / {
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_set_header Connection "";
proxy_redirect off;
proxy_http_version 1.1;
proxy_pass http://nodebeats;
add_header Cache-Control no-cache;
proxy_read_timeout 60s;
}
}
}