Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I'm trying to get my first nginx server setup, and am having trouble setting up ipv4 and ipv6.

I have this in the top of my config file (it's the only server block in the config file):

    server {

            # Listen for requests on these ports 
            listen 80 default;
            listen [::]:80 default_server;
    }

And this is the error I get when I try to start ngnix:

* Restarting nginx nginx
nginx: [emerg] bind() to [::]:80 failed (98: Address already in use)
nginx: [emerg] bind() to [::]:80 failed (98: Address already in use)
nginx: [emerg] bind() to [::]:80 failed (98: Address already in use)
nginx: [emerg] bind() to [::]:80 failed (98: Address already in use)
nginx: [emerg] bind() to [::]:80 failed (98: Address already in use)
nginx: [emerg] still could not bind()

Any help is appreciated.

share|improve this question
    
For clarification, I'm running Ubuntu 12.10 32bit. –  gbuckingham89 Mar 20 '13 at 21:49

2 Answers 2

up vote 1 down vote accepted

You tried to bind to IPv4 twice.

        listen 80 default;
        listen [::]:80 default_server;

By default (on Linux) the second listen directive binds to both IPv4 and IPv6, unless you explicitly request that it bind only to IPv6 with the ipv6only option.

There are two ways you can resolve this. Choose one (but not both):

  1. Delete the first listen directive as redundant. The second directive will cover both IPv4 and IPv6 connections via IPv4-mapped IPv6. The only down side to this is that your logs will show IPv4 addresses in mapped form, e.g. ::ffff:203.0.113.25.

  2. Add ipv6only=on to the second listen directive.


Note that as of nginx 1.3.4, ipv6only=on is now the default, which makes your original configuration necessary in these later versions. Prior to this, the default was operating system dependent.

share|improve this answer
    
"The second listen directive binds to both IPv4 and IPv6, unless you explicitly request" -- not true; that only happens on Linux, it will never happen on OpenBSD, for example. –  cnst Mar 20 '13 at 21:39

You're running Linux?

Might have to do something like this, then:

    listen [::]:80 ipv6only=on;
    listen 80;
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.