bind failed

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


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
> 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  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

More information about the nginx mailing list