<div dir="ltr"><br><div class="gmail_extra"><br><br><div class="gmail_quote">On 12 February 2013 23:14, Ruslan Ermilov <span dir="ltr"><<a href="mailto:ru@nginx.com" target="_blank">ru@nginx.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div class="im">On Tue, Feb 12, 2013 at 09:10:17PM +0400, ivan babrou wrote:<br>
> Hi, I have a question. It's better to describe with example<br>
> I point one.local and two.local to 127.0.0.1 and create following servers<br>
> in config for nginx:<br>
> server {<br>
> listen 80;<br>
> server_name one.local;<br>
> location / {<br>
> return 404;<br>
> }<br>
> }<br>
> server {<br>
> listen two.local:80;<br>
> server_name two.local;<br>
> location / {<br>
> return 403;<br>
> }<br>
> }<br>
> If I request one.local then 403 is returned. If i change listen for<br>
> one.local to one.local:80 then 404 correctly returned, but only after<br>
> restart, reload doesn't help (that's probably bug too).<br>
> I expect to get 404 if i request one.local even if I listen on all<br>
> addresses. Am I right?<br>
<br>
</div><a href="http://127.0.0.1:80" target="_blank">127.0.0.1:80</a> and *:80 are two different socket addresses,<br>
and when you connect to <a href="http://127.0.0.1:80" target="_blank">127.0.0.1:80</a>, the first one will<br>
be used (two.local in your case). This is not specific<br>
to nginx, it's how sockets work.<br>
<br>
nginx by default optimizes such a config by creating only<br>
one listening socket [1], and pessimizes by using getsockaddr()<br>
to differentiate between multiple sockaddrs. This optimization<br>
can be turned off by using "bind" parameter (or some other<br>
parameters, see [1] for details). Nevertheless, <a href="http://127.0.0.1:80" target="_blank">127.0.0.1:80</a><br>
and *:80 are still two different addresses, and <a href="http://127.0.0.1:80" target="_blank">127.0.0.1:80</a><br>
is more specific than *:80.</blockquote><div><br></div><div style>See below, I only see one listening address in netstat. </div><div style><br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
As to "reload not working", I cannot reproduce this:<br>
<br>
(in my config I always return 200 with "$server_name")<br>
<br>
$ echo 'GET <a href="http://one:8000/" target="_blank">http://one:8000/</a>' | nc 127.0.0.1 8000<br>
two.local<br>
<br>
# here config was changed to listen on <a href="http://127.0.0.1:80" target="_blank">127.0.0.1:80</a><br>
# instead of *:80 for one.local<br>
<br>
# reload (kill -HUP nginx master process)<br>
<br>
$ kill -HUP 33122<br>
$ echo 'GET <a href="http://one:8000/" target="_blank">http://one:8000/</a>' | nc 127.0.0.1 8000<br>
one.local<br></blockquote><div><br></div><div style>I have listen *:80 before reload, then change it to listen one.local:80 and reaload. nginx/1.2.6</div><div style><br></div><div style>Before reload:</div><div style><br>
</div><div style><div>callisto ~ # netstat -ntl | fgrep ':80'</div><div>tcp 0 0 <a href="http://0.0.0.0:80">0.0.0.0:80</a> 0.0.0.0:* LISTEN</div><div><br></div><div style>After reload:</div>
<div style><br></div><div style><div>callisto ~ # netstat -ntl | fgrep ':80'</div><div>tcp 0 0 <a href="http://0.0.0.0:80">0.0.0.0:80</a> 0.0.0.0:* LISTEN</div><div><br></div>
<div style>After restart:</div><div style><br></div><div style><div>callisto ~ # netstat -ntl | fgrep ':80'</div><div>tcp 0 0 <a href="http://127.0.0.1:80">127.0.0.1:80</a> 0.0.0.0:* LISTEN</div>
<div><br></div><div style>Did you have one.local and two local when you check this?</div></div></div></div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
[1] <a href="http://nginx.org/r/listen" target="_blank">http://nginx.org/r/listen</a><br>
<div class=""><div class="h5"><br>
_______________________________________________<br>
nginx-devel mailing list<br>
<a href="mailto:nginx-devel@nginx.org">nginx-devel@nginx.org</a><br>
<a href="http://mailman.nginx.org/mailman/listinfo/nginx-devel" target="_blank">http://mailman.nginx.org/mailman/listinfo/nginx-devel</a><br>
</div></div></blockquote></div><br><br clear="all"><div><br></div>-- <br>Regards, Ian Babrou<br><a href="http://bobrik.name" target="_blank">http://bobrik.name</a> <a href="http://twitter.com/ibobrik" target="_blank">http://twitter.com/ibobrik</a> skype:i.babrou
</div></div>