server_name and listen behaviour

ivan babrou ibobrik at gmail.com
Wed Feb 13 04:49:57 UTC 2013


On 12 February 2013 23:06, Igor Sysoev <igor at sysoev.ru> wrote:

> On Feb 12, 2013, at 21:10 , ivan babrou wrote:
>
> > Hi, I have a question. It's better to describe with example
> >
> > I point one.local and two.local to 127.0.0.1 and create following
> servers in config for nginx:
> >
> > server {
> >   listen 80;
> >   server_name one.local;
> >
> >   location / {
> >     return 404;
> >   }
> > }
> >
> > server {
> >   listen two.local:80;
> >   server_name two.local;
> >
> >   location / {
> >     return 403;
> >   }
> > }
> >
> > If I request one.local then 403 is returned. If i change listen for
> one.local to one.local:80 then 404 correctly returned, but only after
> restart, reload doesn't help (that's probably bug too).
>
> Is there in error_log error something like "listen(127.0.0.1:80) failed
> (98: Address already in use)" ?
>

No, there's no such thing.


> > I expect to get 404 if i request one.local even if I listen on all
> addresses. Am I right?
>
>
> No. Your first configuration is
>
> server {
>    listen *:80;
>    server_name  one.local;
> }
>
> server {
>   listen 127.0.0.1:80;
>   server_name  two.local;
> }
>
> A client connects to 127.0.0.1:80, so nginx uses the second server to
> processes request.
> When you change listen in the first server to 127.0.0.1:80, nginx has two
> servers for this
> listen port and chooses server using "Host" header.
>

This is what netstat says:

callisto ~ # netstat -ntl
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address           Foreign Address         State

tcp        0      0 127.0.0.1:21213         0.0.0.0:*               LISTEN

tcp        0      0 0.0.0.0:80              0.0.0.0:*               LISTEN

tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN

tcp        0      0 0.0.0.0:5432            0.0.0.0:*               LISTEN

tcp6       0      0 ::1:21213               :::*                    LISTEN

tcp6       0      0 :::22                   :::*                    LISTEN

tcp6       0      0 :::5432                 :::*                    LISTEN

Here I only see 0.0.0.0:80 and 127.0.0.1:80 looks like a subset for this.
So why can't nginx use the same socket?


> --
> Igor Sysoev
> http://nginx.com/support.html
>
> _______________________________________________
> nginx-devel mailing list
> nginx-devel at nginx.org
> http://mailman.nginx.org/mailman/listinfo/nginx-devel
>



-- 
Regards, Ian Babrou
http://bobrik.name http://twitter.com/ibobrik skype:i.babrou
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.nginx.org/pipermail/nginx-devel/attachments/20130213/021a9d5c/attachment.html>


More information about the nginx-devel mailing list