# Ipv4 & ipv6 Virtual Hosting - address in use

**URL:** <https://www.ruby-forum.com/t/ipv4-ipv6-virtual-hosting-address-in-use/199945>\
**Category:** NGINX\
**Created:** [December 1, 2010, 8:30pm UTC](https://www.ruby-forum.com/t/ipv4-ipv6-virtual-hosting-address-in-use/199945 "2010-12-01T20:30:30Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![Dobai-Pataky\_BSSSSl](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/77aa72/32.png) [@Dobai-Pataky\_BSSSSl](https://www.ruby-forum.com/u/Dobai-Pataky_BSSSSl)\
**Post date:** [December 1, 2010, 8:30pm UTC](https://www.ruby-forum.com/t/ipv4-ipv6-virtual-hosting-address-in-use/199945/1 "2010-12-01T20:30:30Z")

</div>

I have latest nginx configured;

I have one that is purely ipv6 and one that is purely ipv4;

They both work fine in a multi-server environment;

server {  
listen 80;

# listen [::]:80 ipv6only=on;

```
     server_name domain1.com;

     #charset koi8-r;

     #access_log logs/host.access.log main;

     location / {
         root html;
         index index.html index.htm;
     }

```

}

server {  
listen 80;

# listen [::]:80 ipv6only=on;

```
     server_name domain2.com;

     #charset koi8-r;

     #access_log logs/host.access.log main;

     location / {
         root html;
         index index.html index.htm;
     }

```

}

If I un-comment to bind to ipv6 as well as ipv4; when nginx starts it  
complains the address is in use;

I saw a patch for this here is the post;

But according to that post it has been included in 8.39 I am using 8.53

---

<div class="post-metadata">

**Author:** ![elegant](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/3ab097/32.png) [@elegant](https://www.ruby-forum.com/u/elegant)\
**Post date:** [December 1, 2010, 9:09pm UTC](https://www.ruby-forum.com/t/ipv4-ipv6-virtual-hosting-address-in-use/199945/2 "2010-12-01T21:09:25Z")

</div>

On Wed, Dec 01, 2010 at 02:24:24PM -0500, David J. wrote:

> ```
> server_name domain1.com;
> 
> ```
> 
> }
> 
> But according to that post it has been included in 8.39 I am using 8.53

What OS do you use ?

This  
listen 80;  
listen [::]:80 ipv6only=on;  
should work, however, if you add “ipv6only=on” to existant configuration  
and reload it using -HUP, then it does not work. You should stop nginx  
and start it again due to the IPV6\_V6ONLY option behaviour.

–  
Igor S.

> **[Igor Sysoev](http://sysoev.ru/en/)**

---

<div class="post-metadata">

**Author:** ![elegant](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/3ab097/32.png) [@elegant](https://www.ruby-forum.com/u/elegant)\
**Post date:** [December 1, 2010, 9:15pm UTC](https://www.ruby-forum.com/t/ipv4-ipv6-virtual-hosting-address-in-use/199945/3 "2010-12-01T21:15:04Z")

</div>

On 1 Dez 2010 19h24 WET, [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> server\_name [domain1.com](http://domain1.com);  
> }
> 
> I saw a patch for this here is the post;
> 
> But according to that post it has been included in 8.39 I am using  
> 8.53

Cf [GitHub - nginxinc/nginx-wiki: ARCHIVED -- Source for the now archived NGINX Wiki section of https://www.nginx.com · GitHub](http://wiki.nginx.org/HttpCoreModule#listen)

AFAIK, it depends on what type of sockets your OS support, IPv4 only,  
IPv4+IPv6 hybrid or IPv4 and IPv6 separate.

If you’re in a OS that supports hybrid sockets then it seems that your  
config is incorrect, in the sense that it assumes separate IPv6 and  
IPv4 sockets.

Also, AFAIK, Linux uses hybrid sockets by default, while FreeBSD uses  
separate sockets for IPv4 and IPv6.

Perhaps someone more knowledgeable than I in OS’ kernel networking  
internals can chime in.

HTH,  
— appa

---

<div class="post-metadata">

**Author:** ![elegant](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/3ab097/32.png) [@elegant](https://www.ruby-forum.com/u/elegant)\
**Post date:** [December 1, 2010, 9:32pm UTC](https://www.ruby-forum.com/t/ipv4-ipv6-virtual-hosting-address-in-use/199945/4 "2010-12-01T21:32:03Z")

</div>

On Wed, Dec 01, 2010 at 03:20:15PM -0500, David J. wrote:

> Thanks for the responses;
> 
> I am running ubuntu 10.10 on these particular instances;
> 
> I was able to get it working however; its going to the first server  
> configured;
> 
> So I am still not quite sure how to fix;
> 
> I will try playing around a bit more.

You should set “ipv6only” option only in one server  
with “default\_server” flag:

server {  
listen 80;  
listen [::]:80 default\_server ipv6only=on;  
server\_name [domain1.com](http://domain1.com);  
…  
}

server {  
listen 80;  
listen [::]:80;  
server\_name [domain2.com](http://domain2.com);  
…  
}

> > > listen 80;  
> > > index index.html index.htm;  
> > > #charset koi8-r;  
> > > it complains the address is in use;
> > 
> > HTH,
> 
> * * *
> 
> nginx mailing list  
> [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
> [mailman.nginx.org archive](http://nginx.org/mailman/listinfo/nginx)

–  
Igor S.

> **[Igor Sysoev](http://sysoev.ru/en/)**

---

<div class="post-metadata">

**Author:** ![elegant](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/3ab097/32.png) [@elegant](https://www.ruby-forum.com/u/elegant)\
**Post date:** [December 1, 2010, 9:25pm UTC](https://www.ruby-forum.com/t/ipv4-ipv6-virtual-hosting-address-in-use/199945/5 "2010-12-01T21:25:47Z")

</div>

Thanks for the responses;

I am running ubuntu 10.10 on these particular instances;

I was able to get it working however; its going to the first server  
configured;

So I am still not quite sure how to fix;

I will try playing around a bit more.

Thanks.

---

<div class="post-metadata">

**Author:** ![elegant](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/3ab097/32.png) [@elegant](https://www.ruby-forum.com/u/elegant)\
**Post date:** [December 27, 2010, 2:42pm UTC](https://www.ruby-forum.com/t/ipv4-ipv6-virtual-hosting-address-in-use/199945/6 "2010-12-27T14:42:45Z")

</div>

Hello!

On Sun, Dec 26, 2010 at 03:36:16PM -0500, petteyg359 wrote:

> net.ipv6.bindv6only is set to 1.  
> Works ok here.

You may want to provide more details, i.e. exact nginx version you  
are using, full config which triggers the problem and OS details.

Maxim D.

---

<div class="post-metadata">

**Author:** ![elegant](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/3ab097/32.png) [@elegant](https://www.ruby-forum.com/u/elegant)\
**Post date:** [December 26, 2010, 9:37pm UTC](https://www.ruby-forum.com/t/ipv4-ipv6-virtual-hosting-address-in-use/199945/7 "2010-12-26T21:37:43Z")

</div>

ipv6only=on seems to behave the opposite of what it should. I have a  
default\_server listening on all interfaces. It works fine using  
listen [::]:80 default\_server;  
listen 80 default\_server;

but if I do  
listen [::]:80 default\_server ipv6only=on;  
listen 80 default\_server;

then I get a bunch of errors about already bound addresses on startup.  
net.ipv6.bindv6only is set to 1.

Posted at Nginx Forum:

> **[Re: ipv4 & ipv6 Virtual Hosting - address in use](https://forum.nginx.org/read.php?2,154862,161268#msg-161268)**
>
> I have latest nginx configured; I have one that is purely ipv6 and one that is purely ipv4; They both work fine in a multi-server environment; server { listen 80; # listen \[::\]:80 ipv6only=on; serv

---

<div class="post-metadata">

**Author:** ![elegant](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/3ab097/32.png) [@elegant](https://www.ruby-forum.com/u/elegant)\
**Post date:** [December 27, 2010, 4:57pm UTC](https://www.ruby-forum.com/t/ipv4-ipv6-virtual-hosting-address-in-use/199945/8 "2010-12-27T16:57:00Z")

</div>

Linux 2.6.34-gentoo-r12 x86\_64 Intel(R) Core™ i7 CPU 930 @ 2.80GHz  
GenuineIntel GNU/Linux

# nginx -V

nginx version: nginx/0.8.53  
TLS SNI support enabled  
configure arguments: --prefix=/usr --sbin-path=/usr/sbin/nginx  
–conf-path=/etc/nginx/nginx.conf  
–error-log-path=/var/log/nginx/error\_log --pid-path=/var/run/nginx.pid  
–lock-path=/var/lock/nginx.lock --user=nginx --group=nginx  
–with-cc-opt=-I/usr/include --with-ld-opt=-L/usr/lib  
–http-log-path=/var/log/nginx/access\_log  
–http-client-body-temp-path=/var/tmp/nginx/client  
–http-proxy-temp-path=/var/tmp/nginx/proxy  
–http-fastcgi-temp-path=/var/tmp/nginx/fastcgi  
–http-scgi-temp-path=/var/tmp/nginx/scgi  
–http-uwsgi-temp-path=/var/tmp/nginx/uwsgi --with-ipv6 --with-pcre  
–without-http\_autoindex\_module --without-http\_browser\_module  
–without-http\_charset\_module --without-http\_geo\_module  
–without-http\_map\_module --without-http\_memcached\_module  
–without-http\_referer\_module --without-http\_ssi\_module  
–without-http\_split\_clients\_module --without-http\_userid\_module  
–with-http\_realip\_module --with-http\_ssl\_module  
–without-mail\_imap\_module --without-mail\_pop3\_module  
–without-mail\_smtp\_module

server {  
listen [::]:80 default\_server;  
listen 80 default\_server;  
return 444;  
}  
#According to docs, this config should fail, because without  
ipv6only=on,  
#this line should automatically listen on ipv4 interfaces also.

# netstat -lp | grep nginx

tcp 0 0 _:http :  
LISTEN 31704/nginx.conf  
tcp6 0 0 [::]:http [::]:_  
LISTEN 31704/nginx.conf

server {  
listen [::]:80 default\_server ipv6only=on;  
return 444;  
}  
#I remove the listen 80 line, and add ipv6only=on

# /etc/init.d/nginx start

- Checking nginx’ configuration …  
the configuration file /etc/nginx/nginx.conf syntax is ok  
configuration file /etc/nginx/nginx.conf test is successful

- Starting nginx …  
[emerg]: bind() to [2a01:4f8:130:9101::3]:80 failed (98: Address already  
in use)  
[emerg]: bind() to [2a01:4f8:130:9101::3]:80 failed (98: Address already  
in use)  
[emerg]: bind() to [2a01:4f8:130:9101::3]:80 failed (98: Address already  
in use)  
[emerg]: bind() to [2a01:4f8:130:9101::3]:80 failed (98: Address already  
in use)  
[emerg]: bind() to [2a01:4f8:130:9101::3]:80 failed (98: Address already  
in use)  
[emerg]: still could not bind()

- start-stop-daemon: failed to start `/usr/sbin/nginx’

- Failed to start nginx

- ERROR: nginx failed to start

Not only does it not work as described, it seems to be trying to bind a  
specific address multiple times, and maybe succeeding the first time,  
because there’s nothing else running on any interface port 80, so it  
fails since it can’t successfully bind the same address a second time.

Posted at Nginx Forum:  
[http://forum.nginx.org/read.php?2,154862,161461#msg-161461](http://forum.nginx.org/read.php?2,154862,161461#msg-161461)

---

<div class="post-metadata">

**Author:** ![elegant](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/3ab097/32.png) [@elegant](https://www.ruby-forum.com/u/elegant)\
**Post date:** [December 27, 2010, 6:08pm UTC](https://www.ruby-forum.com/t/ipv4-ipv6-virtual-hosting-address-in-use/199945/9 "2010-12-27T18:08:30Z")

</div>

Hello!

On Mon, Dec 27, 2010 at 10:55:35AM -0500, petteyg359 wrote:

> –http-log-path=/var/log/nginx/access\_log  
> –with-http\_realip\_module --with-http\_ssl\_module  
> #this line should automatically listen on ipv4 interfaces also.  
> This shouldn’t fail as long as you have ipv6-only bind as  
> default in your system. It won’t even fail on OSes where binds on  
> ipv6 with ipv4 doesn’t conflict with ipv4 explicit binds. This is  
> unrelated though.

> #I remove the listen 80 line, and add ipv6only=on  
> in use)  
> [!!]
> 
> - ERROR: nginx failed to start
> 
> Not only does it not work as described, it seems to be trying to bind a  
> specific address multiple times, and maybe succeeding the first time,  
> because there’s nothing else running on any interface port 80, so it  
> fails since it can’t successfully bind the same address a second time.

Could you please provide _full config_ which triggers the problem?  
In particular, full list of server{} blocks with their “listen”  
directives.

Maxim D.

---

<div class="post-metadata">

**Author:** ![elegant](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/3ab097/32.png) [@elegant](https://www.ruby-forum.com/u/elegant)\
**Post date:** [October 13, 2011, 3:57pm UTC](https://www.ruby-forum.com/t/ipv4-ipv6-virtual-hosting-address-in-use/199945/10 "2011-10-13T15:57:24Z")

</div>

Hi All,  
I’m a newbie to nginx and facing similar problem in that I cannot bind  
IPv6 address (link local or global):

My nginx.conf is like this:

mail {

# auth\_http 127.0.0.1:8888/cgi-bin/auth.pl;

# auth\_http 127.0.0.1:8888/auth.pl;

```
auth_http 127.0.0.1:8888/popproxy/auth;
auth_http_header X-Auth-Domain "a-sya.com";
auth_http_header X-PopProxy-Secret "popproxy";

```

# auth\_http\_header X-Auth-Domain “ngm1.ocn-test.ne.jp”;

```
auth_http_timeout 15000ms;

```

# after\_auth\_http 127.0.0.1:8888/popproxy-auth/;

```
pop3_auth plain;
pop3_auth apop;
pop3_auth cram-md5;

proxy_pass_error_message on;
server {
    listen 10110;
    listen 127.0.0.1:10110;
    listen [::]:10899;
    # link local address
    #listen [fe80::20c:29ff:fe86:7e4d]:10499; ***1
    # global address
    #listen [fd41:28b7:be11:0:20c:29ff:fe86:7e4d]:10119;

```

\*\*\*2  
protocol pop3;  
server\_name localhost;  
proxy on;  
}  
}

If I uncomments the line marked “\*\*\*1” , the following error occurs:  
nginx: [emerg] bind() to [fe80::20c:29ff:fe86:7e4d]:10499 failed (22:  
Invalid argument)  
If I uncomments the line marked “\*\*\*2”, the following error occurs:  
nginx: [emerg] bind() to [fd41:28b7:be11:0:20c:29ff:fe86:7e4d]:10119  
failed (99: Cannot assign requested address)

Could you tell me why these errors occur?  
I think simply I forget some important configuration though..

Thanks and regards,  
Soichiro MIKI

Maxim D. Wrote:

> Could you please provide _full config_ which  
> triggers the problem?  
> In particular, full list of server{} blocks with  
> their “listen”  
> directives.
> 
> Maxim D.

Posted at Nginx Forum:  
[http://forum.nginx.org/read.php?2,154862,216653#msg-216653](http://forum.nginx.org/read.php?2,154862,216653#msg-216653)
