Dynamic nginx configuration without reloading

Maxim Dounin mdounin at mdounin.ru
Mon Jan 1 20:58:03 UTC 2018


On Mon, Jan 01, 2018 at 12:07:04AM -0600, House Lee wrote:

> We are currently building a shared hosting platform for parts of 
> our clients. We are using nginx as our web servers running on 
> the nodes. 
> Everything works fine. However, we discovered that when we are 
> hosting more than a certain amount of sites (typically around 
> 300 conf files), reloading nginx conf is extremely slow.  
> Is there a way to dynamically configure nginx (e.g. 
> adding/removing server blocks) without reloading nginx? 

Short answer:


Long answer:

There are ways to do limited reconfiguration without reloading, 
notably the API module[1], available as part of our commercial 
subscription.  It won't, however, allow to add or remove server{} 

That is, to add or remove server{} blocks you have to do a 
configuration reload.  Note though, that in many cases you can 
actually avoid adding or removing server{} blocks.  Multiple 
identical or slightly different sites can be handled using a 
single server{} block with multiple server names.

Note well that 300 looks a way too low for "extremely slow", 
you may want to check what actually makes it so slow.  In 
particular, make sure that:

- you do have enough memory, as reload creates a new set of 
  worker processes and this more or less doubles memory used by 

- you don't have problems with DNS and/or no names are used in a 
  configuration.  Slow DNS can easily make loading a 
  configuration with multiple names extremely slow due to blocking 
  DNS lookups during configuration parsing.

[1] http://nginx.org/en/docs/http/ngx_http_api_module.html

Maxim Dounin

More information about the nginx mailing list