Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.debian.user > #228437 > unrolled thread

Can nginx "events" block be configured in an include file?

Started byDave Sherohman <dave@sherohman.org>
First post2020-11-03 11:20 +0100
Last post2020-11-04 07:40 +0100
Articles 6 — 4 participants

Back to article view | Back to linux.debian.user


Contents

  Can nginx "events" block be configured in an include file? Dave Sherohman <dave@sherohman.org> - 2020-11-03 11:20 +0100
    Re: Can nginx "events" block be configured in an include file? Greg Wooledge <wooledg@eeg.ccf.org> - 2020-11-03 14:00 +0100
      Re: Can nginx "events" block be configured in an include file? Dave Sherohman <dave@sherohman.org> - 2020-11-03 15:10 +0100
        Re: Can nginx "events" block be configured in an include file? David Wright <deblis@lionunicorn.co.uk> - 2020-11-03 17:10 +0100
          Re: Can nginx "events" block be configured in an include file? Dave Sherohman <dave@sherohman.org> - 2020-11-04 16:30 +0100
        Re: Can nginx "events" block be configured in an include file? Andrei POPESCU <andreimpopescu@gmail.com> - 2020-11-04 07:40 +0100

#228437 — Can nginx "events" block be configured in an include file?

FromDave Sherohman <dave@sherohman.org>
Date2020-11-03 11:20 +0100
SubjectCan nginx "events" block be configured in an include file?
Message-ID<B71zZ-8l3-13@gated-at.bofh.it>
tl;dr:  I need to increase worker_connections on my nginx servers, but
don't want to edit the debian-provided nginx.conf due to that causing
future upgrade hassles.  Is this possible?


Long version:

I've got a couple servers running a somewhat convoluted web app
deployment, with nginx at the front end.  Every so often, one of the
nginx instances will lock up and start logging "768 worker_connections
are not enough" messages on every request.

After some searches and double-checking that there aren't any loops in
my nginx config, I've come to the conclusion that 768 is an absurdly low
default for production servers - one source said that "over 9000" is
appropriate for most sites that see significant traffic.

So I'm thinking I should probably raise it.  However, when I tried
raising it from conf.d, nginx failed to start, with the error

[emerg] 25402#25402: "events" directive is not allowed here in /etc/nginx/conf.d/mysite.conf:1

conf.d/mysite.conf contains only:
---
events {
  worker_connections 10240;
  # multi_accept on;
}
---

I also tried moving that config file to modules-enabled/ and it at least
gave me a different error message:

[emerg] 14914#14914: "events" directive is duplicate in /etc/nginx/nginx.conf:6

so it apparently accepted my events block, then choked on the default
one.

Is there any way to accomplish this using only new files of my own
creation, while leaving all debian-provided config files in a pristine
state?



I know I could change it directly in /etc/nginx/nginx.conf, but

a) That would potentially generate conflicts with new debian-provided
   versions of nginx.conf whenever the package is upgraded

b) My site-specific config files are generated from templates, meaning
   that I'd then need to keep the template in sync with any debian-
   provided changes, or go outside the existing system and have to
   remember to manually tweak nginx.conf every time I make a new server
   or upgrade an existing one

and I would greatly prefer a one-time change which doesn't lead to
either of those ongoing maintenance concerns.

-- 
Dave Sherohman

[toc] | [next] | [standalone]


#228440

FromGreg Wooledge <wooledg@eeg.ccf.org>
Date2020-11-03 14:00 +0100
Message-ID<B744N-1rd-3@gated-at.bofh.it>
In reply to#228437
On Tue, Nov 03, 2020 at 03:35:58AM -0600, Dave Sherohman wrote:
> tl;dr:  I need to increase worker_connections on my nginx servers, but
> don't want to edit the debian-provided nginx.conf due to that causing
> future upgrade hassles.  Is this possible?

> Is there any way to accomplish this using only new files of my own
> creation, while leaving all debian-provided config files in a pristine
> state?

No.

You will have to edit the nginx.conf file, and this could, in theory,
cause you to need to merge new versions of the nginx.conf file on
release upgrades.

Basically, any section of the nginx.conf file can be split out into
its own separate file, and replaced with an "include" directive in
the main file.

So, copy the "events" block from nginx.conf into your own file with
whatever name you like, and then replace that block with
"include /etc/nginx/yourfile;" in nginx.conf.

Now you can edit yourfile however often you like without needing to
touch nginx.conf any more, at least until a release upgrade.

[toc] | [prev] | [next] | [standalone]


#228441

FromDave Sherohman <dave@sherohman.org>
Date2020-11-03 15:10 +0100
Message-ID<B75ax-2iz-3@gated-at.bofh.it>
In reply to#228440
On Tue, Nov 03, 2020 at 07:57:40AM -0500, Greg Wooledge wrote:
> On Tue, Nov 03, 2020 at 03:35:58AM -0600, Dave Sherohman wrote:
> > tl;dr:  I need to increase worker_connections on my nginx servers, but
> > don't want to edit the debian-provided nginx.conf due to that causing
> > future upgrade hassles.  Is this possible?

> No.

Ah, well.  That's what I expected, but thanks for confirming it.

Another (off-list) reply suggested using a script to edit nginx.conf
rather than doing it by hand, which looks like the best solution for my
specific case.  My site-specific config files are generated from
templates using a Perl deployment script, and I also have hooks there
which I can use to edit nginx.conf without needing to generate the whole
thing from a template, and that will also handle nginx config changes
coming from debian by re-patching the config the next time we deploy.

-- 
Dave Sherohman

[toc] | [prev] | [next] | [standalone]


#228444

FromDavid Wright <deblis@lionunicorn.co.uk>
Date2020-11-03 17:10 +0100
Message-ID<B772G-3rw-3@gated-at.bofh.it>
In reply to#228441
On Tue 03 Nov 2020 at 08:03:24 (-0600), Dave Sherohman wrote:
> On Tue, Nov 03, 2020 at 07:57:40AM -0500, Greg Wooledge wrote:
> > On Tue, Nov 03, 2020 at 03:35:58AM -0600, Dave Sherohman wrote:
> > > tl;dr:  I need to increase worker_connections on my nginx servers, but
> > > don't want to edit the debian-provided nginx.conf due to that causing
> > > future upgrade hassles.  Is this possible?
> 
> > No.
> 
> Ah, well.  That's what I expected, but thanks for confirming it.
> 
> Another (off-list) reply suggested using a script to edit nginx.conf
> rather than doing it by hand, which looks like the best solution for my
> specific case.

I obviously haven't seen that suggestion, but why write a script
yourself when software exists to do that already.

Keep a copy of the original file, and then edit the file so that it
works in the way you require. Now run diff on the two files and
keep the output.

When the package is upgraded and your configuration is modified,¹
you can feed the new file and your diff file into patch, which
will merge them to produce the new configuration +with+ your edits.

Before you do any of this, read   man patch   to get an overview
of what patch can do for you.

> My site-specific config files are generated from
> templates using a Perl deployment script, and I also have hooks there
> which I can use to edit nginx.conf without needing to generate the whole
> thing from a template, and that will also handle nginx config changes
> coming from debian by re-patching the config the next time we deploy.

Patch, of course, has the same pedigree as Perl, both being creations
of Larry Wall.

¹ If your configuration file is actually a package's conffile,
  then much of the work above will be duplicated by the
  installation scripts using the conffile.dpkg-{old,new,tmp}
  mechanism.

Cheers,
David.

[toc] | [prev] | [next] | [standalone]


#228456

FromDave Sherohman <dave@sherohman.org>
Date2020-11-04 16:30 +0100
Message-ID<B7sTv-CM-5@gated-at.bofh.it>
In reply to#228444
On Tue, Nov 03, 2020 at 10:06:30AM -0600, David Wright wrote:
> On Tue 03 Nov 2020 at 08:03:24 (-0600), Dave Sherohman wrote:
> > Another (off-list) reply suggested using a script to edit nginx.conf
> > rather than doing it by hand, which looks like the best solution for my
> > specific case.
> 
> I obviously haven't seen that suggestion, but why write a script
> yourself when software exists to do that already.

Because my deployment script already exists and does several things
other than editing nginx.conf, and I prefer being able to deploy with
one command instead of two.

> Patch, of course, has the same pedigree as Perl, both being creations
> of Larry Wall.

I'm passigly familiar with `patch`, but wasn't aware that Larry was the
original author.  Thanks for that tidbit!

-- 
Dave Sherohman

[toc] | [prev] | [next] | [standalone]


#228452

FromAndrei POPESCU <andreimpopescu@gmail.com>
Date2020-11-04 07:40 +0100
Message-ID<B7kCB-3sw-11@gated-at.bofh.it>
In reply to#228441

[Multipart message — attachments visible in raw view] — view raw

On Ma, 03 nov 20, 08:03:24, Dave Sherohman wrote:
> On Tue, Nov 03, 2020 at 07:57:40AM -0500, Greg Wooledge wrote:
> > On Tue, Nov 03, 2020 at 03:35:58AM -0600, Dave Sherohman wrote:
> > > tl;dr:  I need to increase worker_connections on my nginx servers, but
> > > don't want to edit the debian-provided nginx.conf due to that causing
> > > future upgrade hassles.  Is this possible?
> 
> > No.
> 
> Ah, well.  That's what I expected, but thanks for confirming it.
> 
> Another (off-list) reply suggested using a script to edit nginx.conf
> rather than doing it by hand, which looks like the best solution for my
> specific case.  My site-specific config files are generated from
> templates using a Perl deployment script, and I also have hooks there
> which I can use to edit nginx.conf without needing to generate the whole
> thing from a template, and that will also handle nginx config changes
> coming from debian by re-patching the config the next time we deploy.

Since you're already using Perl, it seems that Config::Model (package 
libconfig-model-perl) can be used to automate configuration updates on 
package upgrade.

Kind regards,
Andrei
-- 
http://wiki.debian.org/FAQsFromDebianUser

[toc] | [prev] | [standalone]


Back to top | Article view | linux.debian.user


csiph-web