Listen on transient address
mdounin at mdounin.ru
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
> [emerg] 1344#1344: bind() to 22.214.171.124:443 failed (99: Cannot
> assign requested address)
> Relevant config:
> listen 172.16.200.5:80 default_server;
> listen 126.96.36.199:80 default_server; # tunnel, not always
> 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:
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:
With this configuration nginx will bind only on *:80, yet
connections to 188.8.131.52:80 will be handled in the second
server, much like with separate listening sockets.
See the description of the "bind" parameter of the "listen"
directive (http://nginx.org/r/listen) for additional details.
More information about the nginx