2

I am running varnish with nginx as proxy on ubuntu and I am getting (24: Too many open files) error every few days. Restarting nginx solves the problem. After researching about this error I found that the common solution is to increase worker_rlimit_nofile in nginx.conf. I feel like this is not a real solution since the limit I will set might reach as well.

Why nginx keeps these files (I believe these are the sockets) open? and what will a solution to my situation?

UPDATE:

I just noticed there are hundreds of varnish sockets open when I run lsof. I believe my issue is that these sockets don't get closed.

guyyug
  • 897
  • 1
  • 11
  • 23

1 Answers1

1

It's a good practice to increase the standard max number of files open on your server when it is a web server, the same goes for the number of ephemeral ports.

I think the default number of opened files is 1024 which is way too small for varnish

I am setting it to 131072

ulimit -n 131072

Benjamin Baumann
  • 4,035
  • 2
  • 25
  • 35
  • Thanks Benjamin. I wondered why these sockets stay open. I stoped passing traffic to the varnish server few days ago and I still see these sockets open and get the same error (24: Too many open files) – guyyug Oct 11 '16 at 06:52
  • I'm no varnish developer but I think each varnish thread manages a socket and since varnish spawns lots of threads (no harm, it's optimized), it needs lots of sockets. If you look at varnish service configuration you should see somewhere `# Open files (usually 1024, which is way too small for varnish) ulimit -n ${NFILES:-131072}` – Benjamin Baumann Oct 11 '16 at 09:36