Nginx 503 error in High traffic

503-errornginx

I have enough memory and cpu but nginx shows 503 error in high traffic.

Here is memory usages

             total       used       free     shared    buffers     cached
Mem:          3383       3370         12          0         37       3071
-/+ buffers/cache:        260       3122
Swap:         4094          0       4094

Also cpu usages never exceeds 20%

top - 13:31:10 up 43 days,  6:47,  3 users,  load average: 0.16, 0.19, 0.22
Tasks:  95 total,   1 running,  92 sleeping,   2 stopped,   0 zombie
Cpu(s):  0.0%us,  0.0%sy,  0.0%ni, 96.7%id,  3.2%wa,  0.0%hi,  0.0%si,  0.2%st
Mem:   3464192k total,  3450844k used,    13348k free,    53248k buffers
Swap:  4192944k total,      100k used,  4192844k free,  3135820k cached

  PID USER      PR  NI  VIRT  RES  SHR S %CPU %MEM    TIME+  COMMAND
    1 root      15   0 10364  648  552 S  0.0  0.0   0:04.33 init
    2 root      RT  -5     0    0    0 S  0.0  0.0   0:14.15 migration/0
    3 root      34  19     0    0    0 S  0.0  0.0   0:00.05 ksoftirqd/0
    4 root      RT  -5     0    0    0 S  0.0  0.0   0:00.00 watchdog/0
    5 root      10  -5     0    0    0 S  0.0  0.0   0:01.10 events/0

I use this code to see active connections: netstat -an |grep :80 |wc -l

Everything is okay when This shows a number under 1500, But when it goes over 1500, users get 503 error.

I have set: worker_processes 2;
and worker_connections 2024;

But still getting this error.

Please help me and suggest how to fix this. And let me know What causing this error. I am using nginx 0.8.55

Thank you.

Best Answer

Try increasing worker_rlimit_nofile and worker_connection, anyway it is good to see whats happening in the error_log. eg:

worker_rlimit_nofile 65535;
events {
    worker_connections  65535;
}