Listen on transient address

Maxim Dounin mdounin at
Fri Nov 16 11:41:01 UTC 2018


On Thu, Nov 15, 2018 at 11:59:31AM -0800, Roger Fischer wrote:

> I have an NGINX instance that listens on a tunnel (and some 
> other interfaces). When NGINX was restarted while the tunnel was 
> down (tun device and address did not exist), NGINX failed to 
> start.
> [emerg] 1344#1344: bind() to failed (99: Cannot 
> assign requested address)
> Relevant config:
>     listen default_server;
>     listen default_server;   # tunnel, not always 
>     up
> Is there a way to configure NGINX to listen “best effort”, still 
> start even if it can’t bind to the address/port, and 
> periodically retry to bind to the address/port? This would be my 
> preferred solution.

If you want to bind nginx on addesses which are not yet available 
on the host, the best solution is to configure a listening socket 
on the wildcard address:

    listen 80;

Further, if for some reason you want to restrict a particular 
server only to connections to a particular IP address, you can do 
so in additional to the lisening socket on the IP address.  That 
is, configure something like this:

    server {
        listen 80;

    server {

With this configuration nginx will bind only on *:80, yet 
connections to will be handled in the second 
server, much like with separate listening sockets.

See the description of the "bind" parameter of the "listen" 
directive ( for additional details.

Maxim Dounin

More information about the nginx mailing list