nginx: [emerg] open() "/var/log/nginx/domains/DOMAIN.es.error.log" failed (24: Too many open files)

castris

Verified User
Joined
Apr 16, 2021
Messages
117
Location
Arcenillas
Hi


Code:
nginx -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: [emerg] open() "/var/log/nginx/domains/DOMAIN.es.error.log" failed (24: Too many open files)
nginx: configuration file /etc/nginx/nginx.conf test failed

But if restrat and verify status of nginx is all ok.

Code:
❯ systemctl restart nginx
❯ systemctl status nginx
● nginx.service - The nginx HTTP and reverse proxy server
     Loaded: loaded (/etc/systemd/system/nginx.service; enabled; vendor preset: enabled)
    Drop-In: /etc/systemd/system/nginx.service.d
             └─override.conf
     Active: active (running) since Thu 2025-02-06 04:39:30 UTC; 5s ago
    Process: 2466362 ExecStartPre=/usr/sbin/nginx -t -c /etc/nginx/nginx.conf (code=exited, status=0/SUCCESS)
    Process: 2466377 ExecStart=/usr/sbin/nginx -c /etc/nginx/nginx.conf (code=exited, status=0/SUCCESS)
   Main PID: 2466382 (nginx)
      Tasks: 19 (limit: 120572)
     Memory: 698.3M
        CPU: 3.071s
     CGroup: /system.slice/nginx.service
             ├─2466382 "nginx: master process /usr/sbin/nginx -c /etc/nginx/nginx.conf"
             ├─2466383 "nginx: worker process" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" ""
             ├─2466384 "nginx: worker process" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" ""
             ├─2466385 "nginx: worker process" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" ""
             ├─2466386 "nginx: worker process" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" ""
             ├─2466387 "nginx: worker process" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" ""
             ├─2466388 "nginx: worker process" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" ""
             ├─2466389 "nginx: worker process" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" ""
             ├─2466390 "nginx: worker process" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" ""
             ├─2466391 "nginx: worker process" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" ""
             ├─2466392 "nginx: worker process" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" ""
             ├─2466393 "nginx: worker process" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" ""
             ├─2466394 "nginx: worker process" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" ""
             ├─2466395 "nginx: worker process" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" ""
             ├─2466396 "nginx: worker process" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" ""
             ├─2466397 "nginx: worker process" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" ""
             ├─2466398 "nginx: worker process" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" ""
             ├─2466399 "nginx: cache manager process" "" "" "" "" "" "" "" "" "" "" "" ""
             └─2466400 "nginx: cache loader process" "" "" "" "" "" "" "" "" "" "" "" "" ""

Feb 06 04:39:28 srv120 systemd[1]: Starting The nginx HTTP and reverse proxy server...
Feb 06 04:39:29 srv120 nginx[2466362]: nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
Feb 06 04:39:29 srv120 nginx[2466362]: nginx: configuration file /etc/nginx/nginx.conf test is successful
Feb 06 04:39:30 srv120 systemd[1]: Started The nginx HTTP and reverse proxy server.

Tests and search issue

Inusual number of file open
Code:
 lsof -u nginx | wc -l
21229

If I use a temporal solution such
Code:
 bash -c 'ulimit -n 65535 && nginx -t'
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful

Other explored possibilities do not help me with the problem.
Has anyone ever faced this before?
The number of files opened by nginx seems very high to me, but it shouldn't be a problem.

Best regards.
 
on old DA installations (5+ years) was 4096, and was fixed as you described, on new installations it already 65535 in nginx service config:
/etc/systemd/system/nginx.service
 
Hi:

fixed, but fail...

I need edit this file ´/etc/security/limits.conf/` adding:
Code:
root soft nofile 65535
root hard nofile 65535

Is a Ubunut 22.04.5 LTS installed latest year on August.

On `nginx.service`I see, but issue is here.
Code:
[Service]
Type=forking
PIDFile=/var/run/nginx.pid
ExecStartPre=/usr/sbin/nginx -t -c /etc/nginx/nginx.conf
ExecStart=/usr/sbin/nginx -c /etc/nginx/nginx.conf
ExecReload=/bin/kill -s HUP $MAINPID
ExecStop=/bin/kill -s QUIT $MAINPID
PrivateTmp=true
LimitMEMLOCK=infinity
LimitNOFILE=65535
 
Back
Top