If Directadmin fails to write customization into NGINX configs with an error: Unable to write customization and details complaining about Too many open files when checking its configuration. That happens due to a system limit on Max open files set on Directadmin processes.
First make sure and check what limit do you have:
for pid in $(pidof directadmin); do grep "^Max open files" /proc/$pid/limits; done;
You should see something similar to the following output:
Max open files 1024 4096 files Max open files 1024 4096 files Max open files 1024 4096 files Max open files 1024 4096 files
That's the limit! To relax the limit do the following
Historically, resource limits for processes are defined in /etc/security/limits.conf. This file is read at login time for users logging in with PAM (via file pam_limits.so). However, RHEL 7 system services that are started via systemd do not use PAM for login, so the limits in /etc/security/limits.conf are ignored.
Update section [Service] of the file: /etc/systemd/system/directadmin.service and bring it to the suggested view:
[Service] Type=forking LimitNOFILE=32768 PIDFile=/run/directadmin.pid ExecStart=/etc/systemd/scripts/directadmin start ExecReload=/etc/systemd/scripts/directadmin reload ExecStop=/etc/systemd/scripts/directadmin stop WorkingDirectory=/usr/local/directadmin
Here we added one line: LimitNOFILE=32768. You can change the limit to whatever you need or want.
Now the right time to reload a configuration and restart the daemon with:
systemctl daemon-reload systemctl restart directadmin
At the top of the file /etc/init.d/directadmin, but below the line:
ulimit -HSn 32768
You should be fine with modifying PAM limits in /etc/security/limits.d/90-nproc.conf or /etc/security/limits.conf
root soft nofile 32768 root hard nofile 48000
Re-login and re-start Directadmin.
We expect to see something similar to the following:
# for pid in $(pidof directadmin); do grep "^Max open files" /proc/$pid/limits; done; Max open files 32768 48000 files Max open files 32768 48000 files Max open files 32768 48000 files Max open files 32768 48000 files
And of course Directadmin should allow us to save customization for NGINX.