Forum: NGINX some question about server listen

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
zhijianpeng (Guest)
on 2009-04-27 18:00
(Received via mailing list)
========my nginx.conf===========
server {

               listen                 10.1.1.1:80;
               server_name             www.test1.com;
               root /opt/test1;
       }

server {

               listen                 80;
               server_name             www.test2.com;
               root /opt/test2;
       }

 ========my nginx.conf===========
I found that server www.test2.com not listen on 10.1.1.1  ,but only
listen on 127.0.0.1,why ?

Posted at Nginx Forum:
http://forum.nginx.org/read.php?2,1455,1455#msg-1455
Igor S. (Guest)
on 2009-04-27 18:12
(Received via mailing list)
On Mon, Apr 27, 2009 at 09:50:27AM -0400, zhijianpeng wrote:

>                listen                 80;
>                server_name             www.test2.com;
>                root /opt/test2;
>        }
>
>  ========my nginx.conf===========
> I found that server www.test2.com not listen on 10.1.1.1  ,but only listen on 
127.0.0.1,why ?

Probably, you mistook: in this case nginx listen on *:80 only.

If you want to bind() to an address, then you should set
     listen    10.1.1.1:80  default bind;
zhijianpeng (Guest)
on 2009-04-28 23:28
(Received via mailing list)
Igor S. Wrote:
-------------------------------------------------------
> >                root /opt/test1;
> >  ========my nginx.conf===========
>
> --
> Igor S.
> http://sysoev.ru/en/

Yes,I saw that nginx listen  on 0.0.0.0:80
but when I use :
curl -v -H "Host:  www.test2.com" http://10.1.1.1/index.html
I get the result of www.test1.com/index.html,

and use
curl -v -H "Host:  www.test2.com" http://127.0.0.1/index.html
then get the result of www.test2.com/index.html

In this case ,does "listen *:80" means    this virtual_server only bind
to the  ip address not used by any other virtual_server?

Posted at Nginx Forum:
http://forum.nginx.org/read.php?2,1455,1475#msg-1475
Igor S. (Guest)
on 2009-04-29 01:49
(Received via mailing list)
On Mon, Apr 27, 2009 at 10:14:41PM -0400, zhijianpeng wrote:

> > >                server_name
> > >        }
> >      listen    10.1.1.1:80  default bind;
>
> and use
> curl -v -H "Host:  www.test2.com" http://127.0.0.1/index.html
> then get the result of www.test2.com/index.html
>
> In this case ,does "listen *:80" means    this virtual_server only bind to the  ip 
address not used by any other virtual_server?

Although nginx listen on *:80, nevertheless it tests an address where
a request was sent to, as if nginx was bind() to the address. It
emulates
usual socket bind() behaviour.
This topic is locked and can not be replied to.