Nginx not spawning both ipv4 and ipv6 workers

Maxim Dounin mdounin at
Tue Jul 26 16:42:06 UTC 2016


On Mon, Jul 25, 2016 at 05:24:46PM -0700, Charles Lawrence wrote:

> I'm in the process of setting up a new server built on ubuntu 16.04
> using nginx 1.10.0.
> The specific issue is that while my new configuration essentially
> matches my old nginx configuration from an ubuntu 13.10 server using
> nginx 1.4.4, nginx 1.10.0 is only creating either ipv4 or ipv6
> workers, but not both. This behavior is not present on the old server.
> Not sure what else to try at this point.

Workers are not bound to IPv6 / IPv4.  Instead, all workers listen 
on all listening sockets configured.


> >   include /etc/nginx/conf.d/*.conf;
> >   include /etc/nginx/sites-enabled/*;
> > }

Note: such configurations are very error-prone, as all files from 
a directory are included without any filtering.  This is known to 
cause unintended inclusion of various "swap", "temp" and "backup" 

For proper testing you may want to comment out the "include" 
directives, and use server{} blocks directly written in 

> Lastly, the weird thing is whether the workers get bound to ipv4 or
> ipv6 entirely depends on the order in which the listen directives are
> placed. In the following data, I've switched the order and tried
> different configurations multiple times. After each change to
> /etc/nginx/sites-enabled/blog I did sudo service nginx stop; sudo
> service nginx start; sudo lsof -i;to get the data.
> Also note that I changed the workers count to 8 after performing these
> steps. However while the number of workers increased, the same
> behavior was seen where all workers were either ipv4 or ipv6.
> > listen [::]:80;
> > listen 80;
> > nginx    27675     root    6u  IPv4 204423      0t0  TCP *:http (LISTEN)
> > nginx    27676 www-data    6u  IPv4 204423      0t0  TCP *:http (LISTEN)
> >
> > listen 80;
> > listen [::]:80;
> > nginx    27747     root    6u  IPv6 205134      0t0  TCP *:http (LISTEN)
> > nginx    27748 www-data    6u  IPv6 205134      0t0  TCP *:http (LISTEN)
> >
> > listen 80;
> > listen [::]:80 default ipv6only=on;
> > nginx    27819     root    6u  IPv6 205849      0t0  TCP *:http (LISTEN)
> > nginx    27820 www-data    6u  IPv6 205849      0t0  TCP *:http (LISTEN)
> >
> > listen 80;
> > listen [::]:80 default ipv6only=off;
> > nginx    27885     root    6u  IPv6 206495      0t0  TCP *:http (LISTEN)
> > nginx    27886 www-data    6u  IPv6 206495      0t0  TCP *:http (LISTEN)

Note: such a configuration is not expected to start at all on Linux, 
as IPv6 socket [::]:80 with IPV6_V6ONLY option set to "off" will 
conflict with IPv4 socket *:80.

That is, "sudo service nginx start" is expected to fail.  If it 
doesn't - this indicate that you are testing something different.

To further debug what's going on, consider:

- using a minimal config directly in nginx.conf, see above;

- starting nginx yourself by hand instead of using startup 
  scripts, this will ensure that this isn't something caused by 
  startup scripts;

- make sure to examine all sockets as printed by lsopt, and very 
  the results using other tools (e.g., "ss -nlt").

Maxim Dounin

More information about the nginx mailing list