ngnix 在连接完成后不会关闭套接字。我在 Google 上搜索过,除了下面提供的之外,找不到任何可以告诉 nginx 关闭此连接的方法:keepalive_timeout 0
。
在请求和响应标头中,我都可以看到Connection: close
,但套接字仍然处于该TIME_WAIT
状态约一分钟。
tcp 0 0 127.0.0.1:80 127.0.0.1:40345 TIME_WAIT -
以下是标题:
Request Headers:
Connection: close
Content-Type: application/x-www-form-urlencoded
Response headers:
HTTP/1.1 200 OK
Server: nginx/0.7.67
Date: Thu, 21 Apr 2011 15:34:31 GMT
Content-Type: text/xml; charset=utf-8
Transfer-Encoding: chunked
Connection: close
我的 nginx 配置的一部分:
nginx 配置文件:
{
...
keepalive_timeout 0;
client_max_body_size 1M;
fastcgi_read_timeout 60;
fastcgi_send_timeout 60;
location ~ \.php$ {
fastcgi_pass unix:/tmp/php-fastcgi.sock;
#fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_intercept_errors on; # to support 404s for PHP files not found
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
fastcgi_param SERVER_NAME $host;
}
}
答案1
在 TIME_WAIT 状态下等待几分钟是设计使然,请查看以下链接了解完整说明:
http://developerweb.net/viewtopic.php?id=2941 http://www.ssfnet.org/Exchange/tcp/tcpTutorialNotes.html