Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have a nginx server with load balancing and reverse proxy. Right now its behing another nginx but very soon I plan to make it front, where it will receive TCP connections from clients directly at a rate of 500req/second

I am having some big troubles with the server. I have pasted my configurations here and I am kinda sure that the problem is with ipconntrac and similar things which are alient to me

root@load_balancer:/proc/sys/net/ipv4# netstat -an|awk '/tcp/ {print $6}'|sort|uniq -c
     67 CLOSING
    173 FIN_WAIT1
    183 FIN_WAIT2
     19 LAST_ACK
      5 LISTEN
    447 SYN_RECV
      1 SYN_SENT
  27970 TIME_WAIT

Its a ubuntu machine with mainly nginx (load balancer and reverse proxy) installed.

It surely isnt great. Can you help me understand whats going on and how can I fix it. This is my live server and I am sure its in a bad shape right now. Any document or commands to fix this, or settings I should make to make this better and reduce time wait and fin_wait1/2 better would be awesome.

share|improve this question
root@li235-57:/proc/sys/net# cat ./nf_conntrack_max 65536 – Sparsh Gupta Feb 7 '11 at 20:59
up vote 7 down vote accepted

Try the following:

echo 1 > /proc/sys/net/ipv4/tcp_tw_recycle
echo 1 > /proc/sys/net/ipv4/tcp_tw_reuse

Probably it will help to reduce the number of TIME_WAIT connections. You can also make these changes permanent in /etc/sysctl.conf:

share|improve this answer
+1 for a solution that works. However I don't know why, and as a developer, it hurts my head to understand this.... – Pham Huy Anh May 10 at 12:20

TIME_WAIT is the state connections go into when you use the Keep Alive feature. The default is to keep connections alive for 75 seconds as Nginx uses hardly any resources to just keep an open connection. If you feel this is to excessive for your OS or needs you can reduce it (or remove it).

share|improve this answer
Nope. TIME_WAIT is nothing to do with this - TIME_WAIT is when a connection has been closed. – Mez Jan 18 '12 at 10:44
Yeah and keep alive will keep it in TIME_WAIT state instead of fully closing the connection. But thanks for the incorrect downvote. – Martin Fjordvald Jan 18 '12 at 15:50
No, it won't. KeepAlive will keep it in ESTABLISHED. – Mez Jan 20 '12 at 16:34

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.