Bug in listen in 0.6.{32,35}?


#1

Hey All,

We’re extremely happily using nginx 0.5.blah for much hosting.
0.5.x isn’t broke, so we have no plans to “fix” it in the forseable
future. However, we have a good use for gzip_static, so have to move to
0.6.x for some servers.

I’m having trouble converting our config style from 0.5.x to 0.6.x,
“listen” isn’t working how it used to, or how the documentation says it
should.
Each server has it’s own IP address, and a series of extra IP addresses
for serving content. To save serious headaches we need to use the same
config on multiple machines, in different data centres.
Previously a config like this worked as expected:

server {
listen *:80 default bind;
server_name hostname1.dc1.blah hostname2.dc1.blah hostname.dc2.blah
}
server {
listen 192.168.36.20:80;
listen 192.168.136.20:80;
server_name www.blah.com;
}
server {
listen 192.168.36.20:80;
listen 192.168.136.20:80;
server_name www.foo.com;
}

nginx would bind to *:80 and not complain that it doesn’t have any of
the other IPs.
With nginx 0.6.35 (and 0.6.32) that configuration fails the test, and
logs this:

2009/04/15 17:12:19 4767#0: bind() to 192.168.36.80:80 failed (99:
Cannot assign requested address)

If I take out listen directives for IPs this machine does not have, the
config test passes, but it still won’t start, with logs like this:

2009/04/15 17:02:20 4702#0: bind() to 127.0.0.1:80 failed (98: Address
already in use)
2009/04/15 17:02:20 4702#0: bind() to 192.168.136.80:80 failed (98:
Address already in use)
2009/04/15 17:02:20 4702#0: try again to bind() after 500ms
2009/04/15 17:02:20 4702#0: bind() to 127.0.0.1:80 failed (98: Address
already in use)
2009/04/15 17:02:20 4702#0: bind() to 192.168.136.80:80 failed (98:
Address already in use)
2009/04/15 17:02:20 4702#0: try again to bind() after 500ms
2009/04/15 17:02:20 4702#0: still could not bind()

Am I missing something, or should this not have worked before (in which
case, what should I be doing?), or have I found a bug?

Many thanks
Mike

Posted at Nginx Forum:
http://forum.nginx.org/read.php?2,1079,1079#msg-1079


#2

If I remember correctly u can not have more then one server config with
the same port in the same config file. Give each URL it’s own file using
vhosts. There is an example in the wiki.

Posted at Nginx Forum:
http://forum.nginx.org/read.php?2,1079,1083#msg-1083


#3

On Wed, Apr 15, 2009 at 12:53:57PM -0400, mikew wrote:

listen *:80 default bind;
server_name www.foo.com;
2009/04/15 17:02:20 4702#0: bind() to 192.168.136.80:80 failed (98: Address already in use)
2009/04/15 17:02:20 4702#0: try again to bind() after 500ms
2009/04/15 17:02:20 4702#0: bind() to 127.0.0.1:80 failed (98: Address already in use)
2009/04/15 17:02:20 4702#0: bind() to 192.168.136.80:80 failed (98: Address already in use)
2009/04/15 17:02:20 4702#0: try again to bind() after 500ms
2009/04/15 17:02:20 4702#0: still could not bind()

Am I missing something, or should this not have worked before (in which case, what should I be doing?), or have I found a bug?

I can not reproduce these errors on 0.6.36 with above configuration:
in my test nginx binds to the *:80 only.


#4

nginx would bind to *:80 and not complain that it doesn’t have any of the other IPs.
With nginx 0.6.35 (and 0.6.32) that configuration fails the test, and logs this:

Your error message is saying that it is having a problem binding to port
80 on 127.0.0.1 and 192.168.136.80, not the other IPs listed. Do you
have something else already listening on the port? ‘netstat -lnpt |
grep 80’ or similar could show you what has the port bound.


#5

On Wed, Apr 15, 2009 at 02:31:44PM -0400, SSSlippy wrote:

If I remember correctly u can not have more then one server config with the same port in the same config file. Give each URL it’s own file using vhosts. There is an example in the wiki.

No, this is a valid configuration.


#6

Sorry, I missed a server set to listen on “127.0.0.1” included by
unwanted file caught in a glob.
listen does work how the documentation says it does!

Mike

Posted at Nginx Forum:
http://forum.nginx.org/read.php?2,1079,1088#msg-1088