Welcome! Log In Create A New Profile

Advanced

Re: server_name and listen behaviour

ivan babrou
February 12, 2013 11:58PM
On 12 February 2013 23:14, Ruslan Ermilov <ru@nginx.com> wrote:

> On Tue, Feb 12, 2013 at 09:10:17PM +0400, 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).
> > I expect to get 404 if i request one.local even if I listen on all
> > addresses. Am I right?
>
> 127.0.0.1:80 and *:80 are two different socket addresses,
> and when you connect to 127.0.0.1:80, the first one will
> be used (two.local in your case). This is not specific
> to nginx, it's how sockets work.
>
> nginx by default optimizes such a config by creating only
> one listening socket [1], and pessimizes by using getsockaddr()
> to differentiate between multiple sockaddrs. This optimization
> can be turned off by using "bind" parameter (or some other
> parameters, see [1] for details). Nevertheless, 127.0.0.1:80
> and *:80 are still two different addresses, and 127.0.0.1:80
> is more specific than *:80.


See below, I only see one listening address in netstat.

As to "reload not working", I cannot reproduce this:
>
> (in my config I always return 200 with "$server_name")
>
> $ echo 'GET http://one:8000/' | nc 127.0.0.1 8000
> two.local
>
> # here config was changed to listen on 127.0.0.1:80
> # instead of *:80 for one.local
>
> # reload (kill -HUP nginx master process)
>
> $ kill -HUP 33122
> $ echo 'GET http://one:8000/' | nc 127.0.0.1 8000
> one.local
>

I have listen *:80 before reload, then change it to listen one.local:80 and
reaload. nginx/1.2.6

Before reload:

callisto ~ # netstat -ntl | fgrep ':80'
tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN

After reload:

callisto ~ # netstat -ntl | fgrep ':80'
tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN

After restart:

callisto ~ # netstat -ntl | fgrep ':80'
tcp 0 0 127.0.0.1:80 0.0.0.0:* LISTEN

Did you have one.local and two local when you check this?


> [1] http://nginx.org/r/listen
>
> _______________________________________________
> nginx-devel mailing list
> nginx-devel@nginx.org
> http://mailman.nginx.org/mailman/listinfo/nginx-devel
>



--
Regards, Ian Babrou
http://bobrik.name http://twitter.com/ibobrik skype:i.babrou
_______________________________________________
nginx-devel mailing list
nginx-devel@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx-devel
Subject Author Views Posted

server_name and listen behaviour

ivan babrou 955 February 12, 2013 12:12PM

Re: server_name and listen behaviour

Igor Sysoev 719 February 12, 2013 02:08PM

Re: server_name and listen behaviour

ivan babrou 482 February 12, 2013 11:52PM

Re: server_name and listen behaviour

Igor Sysoev 719 February 12, 2013 11:58PM

Re: server_name and listen behaviour

ivan babrou 558 February 13, 2013 12:08AM

Re: server_name and listen behaviour

Igor Sysoev 728 February 13, 2013 12:20AM

Re: server_name and listen behaviour

Ruslan Ermilov 435 February 12, 2013 02:16PM

Re: server_name and listen behaviour

Igor Sysoev 726 February 12, 2013 02:34PM

Re: server_name and listen behaviour

ivan babrou 486 February 12, 2013 11:58PM

Re: server_name and listen behaviour

Ruslan Ermilov 611 February 13, 2013 03:20AM



Sorry, you do not have permission to post/reply in this forum.

Online Users

Guests: 123
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready