2

Not a dupe: This is not a duplicate of this question. I've already looked into that question. That helps with raising the limit for worker processes, but the nginx master process continues to retain 1024 and 4096 respectively. This latter nuance is what this question is really about.


The problem:

I'm increasing file descriptor limit for nginx in systemd as follows:

1) Create limit.conf in /etc/systemd/system/nginx.service.d/

2) Save the following lines in this file

[Service]
LimitNOFILE=100000

3) Restart nginx via sudo service nginx restart

Now when I do cat /proc/$(ps aux | grep "nginx: master process" | grep -v grep | awk '{print $2}')/limits | grep "Max open files" I can see this limit set up correctly.

However there is a catch!

If I reboot the system and then re-enter it, the default for nginx's master process is back to 1024 and 4096 (I run the aforementioned cat command to find out).

But if I issue sudo service nginx start, the limit increases again as desired.

How do I ensure this setting is not lost on reboots? Would appreciate an illustrative example. I don't want to manually have to issue sudo service nginx restart each time.


p.s. I've made complementary changes in /etc/security/limits.conf and /etc/pam.d/common-session as well. Ask me for more information in case you need it.

Moreover, /etc/systemd/system/multi-user.target.wants/nginx.service contains:

[Unit]
Description=nginx - high performance web server
Documentation=http://nginx.org/en/docs/
After=network-online.target remote-fs.target nss-lookup.target
Wants=network-online.target

[Service]
Type=forking
PIDFile=/var/run/nginx.pid
ExecStart=/usr/sbin/nginx -c /etc/nginx/nginx.conf
ExecReload=/bin/kill -s HUP $MAINPID
ExecStop=/bin/kill -s TERM $MAINPID

[Install]
WantedBy=multi-user.target

But it's 14.04, so that wouldn't have worked any way. What's the best way to accomplish this on Ubuntu 14.04? Would love an illustrative example that actually works.

Hassan Baig
  • 2,325
  • 12
  • 29
  • 48
  • 1
    Then trying to configure systemd really won't work, because there is no systemd. 14.04 will be end of life in a few weeks anyway. You may as well upgrade. – Michael Hampton Feb 04 '19 at 21:12
  • @MichaelHampton: Fair enough. I'm trying that in a separate virtual machine now, let's see if I get through without boot errors by the end of it. As for the scope of this question, if I were to set `LimitNOFILE=100000` in a 14.04 environment, how would you propose I do it? – Hassan Baig Feb 04 '19 at 21:19
  • I honestly don't even remember. It's been a very long time since I had any Linux systems that didn't use systemd. – Michael Hampton Feb 04 '19 at 21:20
  • Possible duplicate of [Can't raise nginx max files opened limit](https://serverfault.com/questions/721752/cant-raise-nginx-max-files-opened-limit) – Thomas Feb 04 '19 at 21:38
  • @Thomas: Already looked into that. That helps with raising the limit for `worker processes`, but the nginx master process continues to retain `1024` and `4096` respectively. – Hassan Baig Feb 04 '19 at 21:44

0 Answers0