﻿id	summary	reporter	owner	description	type	status	priority	milestone	component	version	resolution	keywords	cc	uname	nginx_version
1447	"Specific IP(v4) listen directives cause ""address already in use"" when using ipv6only=off"	indecisivemal@…		"Attempting to have one server block listening on all addresses (v4 and v6) and a second server block listening only on one IPv4 address.

When using ipv6only=off to accomplish the first with a single listen statement, the specific IP listen statement in the second causes nginx to report ""address already in use"" and exit(1):

{{{
Dec 15 01:15:35 mydebian systemd[1]: Starting nginx - high performance web server...
Dec 15 01:15:35 mydebian nginx[20599]: nginx: [emerg] bind() to 127.0.0.1:80 failed (98: Address already in use)
[previous message repeated 4 more times]
Dec 15 01:15:37 mydebian nginx[20599]: nginx: [emerg] still could not bind()
Dec 15 01:15:37 mydebian systemd[1]: nginx.service: Control process exited, code=exited status=1
}}}

Scattering log calls around, it seems like src/http/ngx_http.c ngx_http_add_listen() needs awareness of ipv6only=off so when it tests new proto=AF_INET :80 against existing proto=AF_INET6 :80 it considers it known instead of new.


Example nginx.conf:
{{{
events {}
http {
    server {
        listen [::]:80 ipv6only=off;
    }
    server {
        listen 127.0.0.1:80;
    }
}
}}}

Problem observed with:
Arch nginx-mainline 1.13.7 (Linux myarch 4.14.5-1-ARCH #1 SMP PREEMPT Sun Dec 10 14:50:30 UTC 2017 x86_64 GNU/Linux)
Arch with nginx 1.13.7 from hg, default ./configure
Debian with nginx-mainline from nginx repo (shown)

Both default to net.ipv6.bindv6only=0"	defect	closed	minor		other	1.13.x	wontfix	ipv6only, ngx_http		Linux mydebian 4.9.0-4-grsec-amd64 #1 SMP Debian 4.9.51-1+grsecunoff2~bpo9+1 (2017-10-11) x86_64 GNU/Linux	"nginx version: nginx/1.13.7
built by gcc 6.3.0 20170516 (Debian 6.3.0-18)
built with OpenSSL 1.1.0f  25 May 2017
TLS SNI support enabled
configure arguments: --prefix=/etc/nginx --sbin-path=/usr/sbin/nginx --modules-path=/usr/lib/nginx/modules --conf-path=/etc/nginx/nginx.conf --error-log-path=/var/log/nginx/error.log --http-log-path=/var/log/nginx/access.log --pid-path=/var/run/nginx.pid --lock-path=/var/run/nginx.lock --http-client-body-temp-path=/var/cache/nginx/client_temp --http-proxy-temp-path=/var/cache/nginx/proxy_temp --http-fastcgi-temp-path=/var/cache/nginx/fastcgi_temp --http-uwsgi-temp-path=/var/cache/nginx/uwsgi_temp --http-scgi-temp-path=/var/cache/nginx/scgi_temp --user=nginx --group=nginx --with-compat --with-file-aio --with-threads --with-http_addition_module --with-http_auth_request_module --with-http_dav_module --with-http_flv_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_mp4_module --with-http_random_index_module --with-http_realip_module --with-http_secure_link_module --with-http_slice_module --with-http_ssl_module --with-http_stub_status_module --with-http_sub_module --with-http_v2_module --with-mail --with-mail_ssl_module --with-stream --with-stream_realip_module --with-stream_ssl_module --with-stream_ssl_preread_module --with-cc-opt='-g -O2 -fdebug-prefix-map=/data/builder/debuild/nginx-1.13.7/debian/debuild-base/nginx-1.13.7=. -specs=/usr/share/dpkg/no-pie-compile.specs -fstack-protector-strong -Wformat -Werror=format-security -Wp,-D_FORTIFY_SOURCE=2 -fPIC' --with-ld-opt='-specs=/usr/share/dpkg/no-pie-link.specs -Wl,-z,relro -Wl,-z,now -Wl,--as-needed -pie'"
