Listen and IPV6 behaviour?

Hi all,

How to use the nginx listen diective to listen on all interface (ipv4
and ipv6) and on port 80 ?

I thought “listen [::]:80;” would be enought but it seems that I have
to use both “listen 80;” and “listen [::]:80;”

Is it the normal behaviour or a bug ?

++ Jerome

OS: OpenBSD 4.5 and linux 2.6.28
Im’ using nginx 0.8.22
I’ve enable ipv6 support at compile time with --with-ipv6
I use the default nginx conf file (just the port has been changed to 81)
My server is fully ipv6 compliant.

If I start nginx, it listens on ipv4 only :
listen 81;

root@wild:~/nginx-0.8.22# lsof -i :81
COMMAND PID USER FD TYPE DEVICE SIZE NODE NAME
nginx 18224 root 6u IPv6 26577575 TCP *:81 (LISTEN)
nginx 18225 nobody 6u IPv6 26577575 TCP *:81 (LISTEN)

If I changed the listen directive to:
listen [::]:81;

root@wild:~/nginx-0.8.22# lsof -i :81
COMMAND PID USER FD TYPE DEVICE SIZE NODE NAME
nginx 18224 root 6u IPv6 26577575 TCP *:81 (LISTEN)
nginx 18361 nobody 6u IPv6 26577575 TCP *:81 (LISTEN)

If I use both:
listen [::]:81;
listen 81;

root@raptor> lsof -i :80
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
nginx 23184 nobody 10u IPv6 0xd639be40 TCP *:81 (LISTEN)
nginx 23184 nobody 11u IPv4 0xd639b990 TCP *:81 (LISTEN)
nginx 23235 root 10u IPv6 0xd639be40 TCP *:81 (LISTEN)
nginx 23235 root 11u IPv4 0xd639b990 TCP *:81 (LISTEN)

On Mon, Nov 09, 2009 at 07:17:24PM +0100, Jérôme Loyet wrote:

++ Jerome
root@wild:~/nginx-0.8.22# lsof -i :81
nginx 18361 nobody 6u IPv6 26577575 TCP *:81 (LISTEN)
nginx 23235 root 11u IPv4 0xd639b990 TCP *:81 (LISTEN)
This depends on kernel default ipv6only setting.
For example, in FreeBSD its default value is “net.inet6.ip6.v6only: 1”
In Linux it’s off.

You may try to use
listen [::]:81 ipv6only=on;
listen 81;
to get consistent behaviour.

However, note that ipv6only value can be set only on nginx’s start
before bind().