<div dir="ltr">Francis,<div><br></div><div>Sorry it took so long, I've finally come back to this question.</div><div><br></div><div>The example you gave works great:</div><div><br></div><div><span style="font-size:12.8px"> server {</span><br style="font-size:12.8px"><span style="font-size:12.8px"> listen </span><a href="http://127.0.0.1:8088/" rel="noreferrer" target="_blank" style="font-size:12.8px">127.0.0.1:8088</a><span style="font-size:12.8px">;</span><br style="font-size:12.8px"><span style="font-size:12.8px"> return 200 "listen </span><a href="http://127.0.0.1:8088/" rel="noreferrer" target="_blank" style="font-size:12.8px">127.0.0.1:8088</a><span style="font-size:12.8px">\n";</span><br style="font-size:12.8px"><span style="font-size:12.8px"> }</span><br style="font-size:12.8px"><span style="font-size:12.8px"> server {</span><br style="font-size:12.8px"><span style="font-size:12.8px"> listen </span><a href="http://10.0.1.2:8088/" rel="noreferrer" target="_blank" style="font-size:12.8px">10.0.1.2:8088</a><span style="font-size:12.8px">;</span><br style="font-size:12.8px"><span style="font-size:12.8px"> return 200 "listen </span><a href="http://10.0.1.2:8088/" rel="noreferrer" target="_blank" style="font-size:12.8px">10.0.1.2:8088</a><span style="font-size:12.8px">\n";</span><br style="font-size:12.8px"><span style="font-size:12.8px"> }</span><br style="font-size:12.8px"><span style="font-size:12.8px"> server {</span><br style="font-size:12.8px"><span style="font-size:12.8px"> listen 8088;</span><br style="font-size:12.8px"><span style="font-size:12.8px"> return 200 "listen 8088\n";</span><br style="font-size:12.8px"><span style="font-size:12.8px"> }</span><br></div><div><span style="font-size:12.8px"><br></span></div><div><span style="font-size:12.8px">Where I get into problem is if I do something like this:</span></div><div><span style="font-size:12.8px"><br></span></div><div><span style="font-size:12.8px"> server {</span><br style="font-size:12.8px"><span style="font-size:12.8px"> listen </span><a href="http://127.0.0.1:8088/" rel="noreferrer" target="_blank" style="font-size:12.8px">127.0.0.1:8088</a> backlog=65536 deferred<span style="font-size:12.8px">;</span><br style="font-size:12.8px"><span style="font-size:12.8px"> return 200 "listen </span><a href="http://127.0.0.1:8088/" rel="noreferrer" target="_blank" style="font-size:12.8px">127.0.0.1:8088</a><span style="font-size:12.8px">\n";</span><br style="font-size:12.8px"><span style="font-size:12.8px"> }</span><br style="font-size:12.8px"><span style="font-size:12.8px"> server {</span><br style="font-size:12.8px"><span style="font-size:12.8px"> listen </span><a href="http://10.0.1.2:8088/" rel="noreferrer" target="_blank" style="font-size:12.8px">10.0.1.2:8088</a> backlog=65536 deferred<span style="font-size:12.8px">;</span><br style="font-size:12.8px"><span style="font-size:12.8px"> return 200 "listen </span><a href="http://10.0.1.2:8088/" rel="noreferrer" target="_blank" style="font-size:12.8px">10.0.1.2:8088</a><span style="font-size:12.8px">\n";</span><br style="font-size:12.8px"><span style="font-size:12.8px"> }</span><br style="font-size:12.8px"><span style="font-size:12.8px"> server {</span><br style="font-size:12.8px"><span style="font-size:12.8px"> listen 8088;</span><br style="font-size:12.8px"><span style="font-size:12.8px"> return 200 "listen 8088\n";</span><br style="font-size:12.8px"><span style="font-size:12.8px"> }</span><span style="font-size:12.8px"><br></span></div><div><span style="font-size:12.8px"><br></span></div><div><span style="font-size:12.8px">In that case I get errors like "nginx: [emerg] bind() to <a href="http://0.0.0.0:8088">0.0.0.0:8088</a> failed (98: Address already in use)". So the workaround is obviously not to use those options - I could patch the source to use a backlog larger then 511.</span></div><div><span style="font-size:12.8px"><br></span></div><div><span style="font-size:12.8px">This example also works well:</span></div><div><span style="font-size:12.8px"><br></span></div><div><div style=""><span style="font-size:12.8px"> server {</span></div><div style=""><span style="font-size:12.8px"> listen *:80;</span></div><div style=""><span style="font-size:12.8px"> server_name "test_a";</span></div><div style=""><span style="font-size:12.8px"> return 200 "listen test_a";</span></div><div style=""><span style="font-size:12.8px"> }</span></div><div style=""><span style="font-size:12.8px"><br></span></div><div style=""><span style="font-size:12.8px"> server {</span></div><div style=""><span style="font-size:12.8px"> listen *:80;</span></div><div style=""><span style="font-size:12.8px"> server_name "test_b";</span></div><div style=""><span style="font-size:12.8px"> return 200 "listen test_b";</span></div><div style=""><span style="font-size:12.8px"> }</span></div><div style=""><span style="font-size:12.8px"><br></span></div><div style=""><span style="font-size:12.8px"> server {</span></div><div style=""><span style="font-size:12.8px"> listen *:80 default_server;</span></div><div style=""><span style="font-size:12.8px"> return 200 "listen *";</span></div><div style=""><span style="font-size:12.8px"> }</span></div></div><div style=""><span style="font-size:12.8px"><br></span></div><div style=""><span style="font-size:12.8px">But if I change it to this:</span></div><div style=""><span style="font-size:12.8px"><br></span></div><div style=""><div style=""><span style="font-size:12.8px"> server {</span></div><div style=""><span style="font-size:12.8px"> listen *:80 backlog=65536 deferred;</span></div><div style=""><span style="font-size:12.8px"> server_name "test_a";</span></div><div style=""><span style="font-size:12.8px"> return 200 "listen test_a";</span></div><div style=""><span style="font-size:12.8px"> }</span></div><div style=""><span style="font-size:12.8px"><br></span></div><div style=""><span style="font-size:12.8px"> server {</span></div><div style=""><span style="font-size:12.8px"> listen *:80 backlog=65536 deferred;</span></div><div style=""><span style="font-size:12.8px"> server_name "test_b";</span></div><div style=""><span style="font-size:12.8px"> return 200 "listen test_b";</span></div><div style=""><span style="font-size:12.8px"> }</span></div><div style=""><span style="font-size:12.8px"><br></span></div><div style=""><span style="font-size:12.8px"> server {</span></div><div style=""><span style="font-size:12.8px"> listen *:80 backlog=65536 deferred default_server;</span></div><div style=""><span style="font-size:12.8px"> return 200 "listen *";</span></div><div style=""><span style="font-size:12.8px"> }</span></div><div style=""><span style="font-size:12.8px"><br></span></div><div style=""><span style="font-size:12.8px">Then I get the error message "nginx: [emerg] duplicate listen options for <a href="http://0.0.0.0:80">0.0.0.0:80</a> in /etc/nginx/nginx.conf". I can fix it by doing something like this:</span></div><div style=""><span style="font-size:12.8px"><br></span></div><div style=""><div style=""><span style="font-size:12.8px"> server {</span></div><div style=""><span style="font-size:12.8px"> listen *:80;</span></div><div style=""><span style="font-size:12.8px"> server_name "test_a";</span></div><div style=""><span style="font-size:12.8px"> return 200 "listen test_a";</span></div><div style=""><span style="font-size:12.8px"> }</span></div><div style=""><span style="font-size:12.8px"><br></span></div><div style=""><span style="font-size:12.8px"> server {</span></div><div style=""><span style="font-size:12.8px"> listen *:80;</span></div><div style=""><span style="font-size:12.8px"> server_name "test_b";</span></div><div style=""><span style="font-size:12.8px"> return 200 "listen test_b";</span></div><div style=""><span style="font-size:12.8px"> }</span></div><div style=""><span style="font-size:12.8px"><br></span></div><div style=""><span style="font-size:12.8px"> server {</span></div><div style=""><span style="font-size:12.8px"> listen *:80 backlog=65536 deferred default_server;</span></div><div style=""><span style="font-size:12.8px"> return 200 "listen *";</span></div><div style=""><span style="font-size:12.8px"> }</span></div><div style=""><span style="font-size:12.8px"><br></span></div><div style=""><span style="font-size:12.8px">From the ss -l output I am picking up the larger listen queue which I'm happy about, though its confusing why nginx is picking them from that last server stanza (it has the same behavior without the default_server keyword). If I'm doing a virtual hosting type setup and I'm including all of my server definitions from individual files in a subdirectory, it appears that any one of them could bump up the backlog, but if any two server stanzas have options to do it then it causes an error. Maybe the best way to do it is to have some sort of dummy entry that sets the options - if its always the last server stanza that sets the listen options then maybe include all the other server stanzas and have the dummy at the end that sets the backlog and deferred options?</span></div></div></div><div style=""><span style="font-size:12.8px"><br></span></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Thu, Mar 31, 2016 at 4:29 PM, Francis Daly <span dir="ltr"><<a href="mailto:francis@daoine.org" target="_blank">francis@daoine.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">On Thu, Mar 31, 2016 at 01:21:02PM -0400, CJ Ess wrote:<br>
<br>
Hi there,<br>
<span class=""><br>
> I would like to have an Nginx setup where I have specific logic depending<br>
> on which interface (ip) the request arrived on.<br>
<br>
</span>multiple server{} with different "listen"; possibly with an "include<br>
common-config" entry.<br>
<br>
Note: "listen" is on an ip, not an interface.<br>
<span class=""><br>
> I was able to make this work by having a server stanza for each ip on the<br>
> server, but was't able to do a combination of a specific ip and a wildcard<br>
> ip (as a catchall) - is there a way to do that with some option combination<br>
> (i.e. nginx listens on *:80, but matches the server stanza by ip?)<br>
<br>
</span>I don't understand what you are describing. Could you try again, perhaps<br>
with a config example?<br>
<br>
When I use<br>
<br>
===<br>
server {<br>
listen <a href="http://127.0.0.1:8088" rel="noreferrer" target="_blank">127.0.0.1:8088</a>;<br>
return 200 "listen <a href="http://127.0.0.1:8088" rel="noreferrer" target="_blank">127.0.0.1:8088</a>\n";<br>
}<br>
server {<br>
listen <a href="http://10.0.1.2:8088" rel="noreferrer" target="_blank">10.0.1.2:8088</a>;<br>
return 200 "listen <a href="http://10.0.1.2:8088" rel="noreferrer" target="_blank">10.0.1.2:8088</a>\n";<br>
}<br>
server {<br>
listen 8088;<br>
return 200 "listen 8088\n";<br>
}<br>
===<br>
<br>
I get the following output, which is what I expect:<br>
<br>
$ curl <a href="http://127.0.0.1:8088/" rel="noreferrer" target="_blank">http://127.0.0.1:8088/</a><br>
listen <a href="http://127.0.0.1:8088" rel="noreferrer" target="_blank">127.0.0.1:8088</a><br>
$ curl <a href="http://127.0.0.2:8088/" rel="noreferrer" target="_blank">http://127.0.0.2:8088/</a><br>
listen 8088<br>
<span class=""><br>
> The scenario I'm playing towards is that I have a dedicated connection to a<br>
> CDN and I want to pass thru certain headers if they arrive via the<br>
> dedicated interface, strip them if they arrive on other interface.<br>
<br>
</span>As above, if "interface" is replaced with "ip", this can work with two<br>
server{} blocks.<br>
<span class=""><br>
> When I did the server{} per IP approach nginx complained about duplicate<br>
> listen settings for the second IP even though both server stanzas were<br>
> bound to a specific port/interface. Is this a bug per chance?<br>
<br>
</span>What short server{} config can I use to reproduce the complaint?<br>
<span class="HOEnZb"><font color="#888888"><br>
f<br>
--<br>
Francis Daly <a href="mailto:francis@daoine.org">francis@daoine.org</a><br>
<br>
_______________________________________________<br>
nginx mailing list<br>
<a href="mailto:nginx@nginx.org">nginx@nginx.org</a><br>
<a href="http://mailman.nginx.org/mailman/listinfo/nginx" rel="noreferrer" target="_blank">http://mailman.nginx.org/mailman/listinfo/nginx</a><br>
</font></span></blockquote></div><br></div>