Listen on transient address
Maxim Dounin
mdounin at mdounin.ru
Fri Nov 16 11:41:01 UTC 2018
Hello!
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 38.88.78.19:443 failed (99: Cannot
> assign requested address)
>
> Relevant config:
>
> listen 172.16.200.5:80 default_server;
> listen 38.88.78.19:80 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 {
listen 38.88.78.19:80;
...
}
With this configuration nginx will bind only on *:80, yet
connections to 38.88.78.19: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.
--
Maxim Dounin
http://mdounin.ru/
More information about the nginx
mailing list