bind failed

Maxim Dounin mdounin at mdounin.ru
Tue Dec 1 13:00:59 UTC 2015


Hello!

On Tue, Dec 01, 2015 at 12:49:50AM -0800, Frank Liu wrote:

> Hi,
> 
> I was doing some tests today and have created a single test virtual host
> with
> listen 8181;
> and nginx runs fine (1.9.7). Now if I change the listen to only one
> interface ip:
> listen 192.168.10.10:8181
> configtest shows fine but reload gives "bind failed" in the error log.
> Is this normal?

Short answer:

Yes, if you are using Linux.

Long answer:

Linux doesn't allow listen sockets on INADDR_ANY and an IP address 
on the same port to coexist, due to "security" reasons.  And this 
is exactly what happens when you try to reload a configuration - 
nginx still has an open listening sockets on *:8181 and tries to 
open another one on 192.168.10.10:8181.  As a result, the bind() 
system call fails due to the Linux limitation, and that's what you 
see in the error log.  To switch from a listening on * to an IP 
address on Linux you'll have to restart nginx, reload won't work.

The same process works fine on other OSes without such artificial 
limitations (e.g., FreeBSD).

-- 
Maxim Dounin
http://nginx.org/



More information about the nginx mailing list