我正在尝试诊断 debian 上 nginx 的连接问题。连接上有 2 到 10 秒的延迟,我使用 curl 进行测试:
curl -o /dev/null -w "Connect: %{time_connect} TTFB: %{time_starttransfer} Total time: %{time_total} \n" -s http://example.com/forumhome.css
Connect: 0.657 TTFB: 1.183 Total time: 7.150
这里是上述 curl 请求的 tcpdump 输出的 pastebin:http://pastebin.com/2tdZHqFr
我也从不同位置使用pagetest.org进行了测试,但存在相同的连接问题。
这些文件由安装在另一台机器上的 SSD 提供。
Linux main 2.6.32-5-amd64 #1 SMP 2011 年 5 月 18 日星期三 23:13:22 UTC x86_64 GNU/Linux
nginx 配置:
user www-data;
worker_processes 4;
worker_rlimit_nofile 802768;
error_log /var/log/nginx/error.log;
pid /var/run/nginx.pid;
events {
use epoll;
worker_connections 60000;
multi_accept on;
}
http {
include /etc/nginx/mime.types;
# access_log /var/log/nginx/access.log;
access_log off;
sendfile off;
keepalive_timeout 75;
tcp_nodelay on;
keepalive_requests 2000;
connection_pool_size 8192;
client_body_buffer_size 1024K;
client_header_buffer_size 8k;
client_max_body_size 10M;
fastcgi_buffers 4 256k;
fastcgi_buffer_size 128k;
fastcgi_busy_buffers_size 256k;
large_client_header_buffers 8 8k;
ignore_invalid_headers on;
client_header_timeout 60;
client_body_timeout 60;
send_timeout 60;
output_buffers 8 32k;
postpone_output 0;
server_name_in_redirect off;
server_tokens off;
tcp_nopush on;
gzip on;
gzip_min_length 1100;
gzip_buffers 32 8k;
gzip_comp_level 2;
gzip_types text/plain text/html application/x-javascript text/xml text/css text/javascript;
gzip_vary on;
include /etc/nginx/conf.d/*.conf;
include /etc/nginx/sites-enabled/*;
}
sysctl 在这里 ->pastebin 系统
站点.conf:
open_file_cache max=5000 inactive=20s;
open_file_cache_valid 30s;
open_file_cache_min_uses 2;
open_file_cache_errors on;
server {
listen 80 ; ## listen for ipv4
server_name example.com;
root /mnt/ssd/www/static;
location ~* \.(css|js)$ {
expires max;
add_header Pragma public;
add_header Cache-Control "public, must-revalidate, proxy-revalidate";
}
}
如果配置 eth0:
eth0 Link encap:Ethernet HWaddr 00:15:17:26:b4:bd
inet addr:x.x.x.x Bcast:x.x.x.x Mask:255.255.254.0
inet6 addr: fe80::215:17ff:fe26:b4bd/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:9000 Metric:1
RX packets:1136534270 errors:0 dropped:0 overruns:0 frame:0
TX packets:623191419 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:174357516836 (162.3 GiB) TX bytes:323522620298 (301.3 GiB)
Memory:e1a00000-e1a20000
猫/ proc / CPU信息:
model name : Intel(R) Core(TM)2 Quad CPU Q6600 @ 2.40GHz
猫/ proc / meminfo:
MemTotal: 4058884 kB
MemFree: 3366684 kB
Buffers: 117632 kB
Cached: 288320 kB
答案1
最好检查一下正向和(尤其是)反向 DNS 查找。这是导致“速度慢”的常见原因。