Skip to content

Instantly share code, notes, and snippets.

@rlipscombe
Created October 23, 2018 12:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rlipscombe/926f38f8a51eb4201ebbbae9d22f517a to your computer and use it in GitHub Desktop.
Save rlipscombe/926f38f8a51eb4201ebbbae9d22f517a to your computer and use it in GitHub Desktop.
Increasing nginx file limits

I needed to load-test an HTTP client, so I used nginx. I ran into some limits:

2018/10/17 23:44:09 [alert] 1860#1860: 768 worker_connections are not enough

To get around this, edit /etc/nginx/nginx.conf and edit the events section:

events {
        worker_connections 5000;
        # multi_accept on;
}

Then restart nginx:

sudo service nginx restart

Once I'd done that, I started running into "too many open files" errors:

2018/10/23 13:33:50 [crit] 19813#19813: accept4() failed (24: Too many open files)
2018/10/23 13:33:51 [crit] 19813#19813: *1127 open() "/var/www/html/index.nginx-debian.html" failed (24: Too many open files), client: 127.0.0.1, server: _, request: "GET / HTTP/1.1", host: "localhost:8443"

To resolve this, we need to bump the open file limit for the worker processes.

First, though, let's see what the default is:

sudo cat /proc/$(ps -ef | awk -v pid=$(cat /run/nginx.pid) '$3 == pid {print $2;exit}')/limits | \
    grep 'Max open files'

Yeah, that looks complicated, but it won't get confused if you're running another instance of nginx in a (docker) container.

It turns out that, with no further modifications, the limit is 1024.

Let's try to increase that. Edit /etc/nginx/nginx.conf so that the start of the file looks like the following:

user www-data;
worker_processes auto;
worker_rlimit_nofile 5120;
pid /run/nginx.pid;

Then restart nginx:

sudo service nginx restart

Confirm the new limit with the monstrosity from earlier.

Linux Mint 18.3 (i.e. Ubuntu 16.04)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment