The following error occurred a lot in /var/log/nginx/error.log:
Too many open files
This means that the nginx master process reached the maximum number of open files which was set to the default of 4096. (To check it, simply cat /proc/pid/limits, where pid is the process id)
To resolve, this, edit /lib/systemd/system/nginx.service and add the following line:
LimitNOFILE=30000 #change it according to your needs
Then reload the systemctl daemon:
sudo systemctl daemon-reload
and finally restart the nginx service:
sudo service nginx restart
That’s it, the error is gone!
Tested on Ubuntu 16.04 with nginx 1.17, should work with any other OS using systemd.