nginx on multi ip address

Jonathan Matthews contact at jpluscplusm.com
Tue Dec 11 12:22:29 UTC 2012


On 11 December 2012 11:54, adam sun <lists at ruby-forum.com> wrote:
> My webserver has two ip(192.168.0.10 and 200.12.12.10).
> And I have many hosts running on these ip.
>
> most of them configured like this:
>
> server {
>       server_name server1;
>       listen 80;
> };
>
> server {
>       server_name server2;
>       listen 80;
> };
>
> #........
>
> Then I would like to make "server1" only listen to internal ip
> address(192.168.0.10).
> And I changed the server1 conf to
> server {
>       server_name server1;
>       listen 192.168.0.10:80;
> };
>
> and keep everything else as before.
>
> Now I got problem.
> When I visit  server2 using ip 192.168.0.10, the server will give me
> response of server1.
>
>
> Is there anyway to resolve this?

Along with the IP-specific server{} blocks you've created, set up a
default server which doesn't have an affinity to any site.
e.g.

server {
  listen 192.168.0.10:80 default_server;
  listen 200.12.12.10:80 default_server;
  server_name _;
  return 444; # or redirect, or whatever is appropriate
}

HTH
Jonathan
-- 
Jonathan Matthews // Oxford, London, UK
http://www.jpluscplusm.com/contact.html



More information about the nginx mailing list