How to fix nginx "too many open files" error?

As root:

systemctl edit nginx.service

This will open the file /etc/systemd/system/nginx.service.d/override.conf so you need to add two lines between the comments, as shown below:

### Editing /etc/systemd/system/nginx.service.d/override.conf
### Anything between here and the comment below will become the new contents of the file

[Service]
LimitNOFILE=250000

### Lines below this comment will be discarded

### /etc/systemd/system/nginx.service

Save the file and restart nginx

systemctl restart nginx.service

Check again the limits and also nginx:

cat /proc/$(cat /var/run/nginx.pid)/limits | grep -i 'Max open files'

nginx -t

1 Like