Forum: NGINX nginx on multi ip address

Posted by adam sun (adamsunyu)
on 2012-12-11 12:54
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?
Posted by Francis Daly (Guest)
on 2012-12-11 13:14
(Received via mailing list)
On Tue, Dec 11, 2012 at 12:54:06PM +0100, adam sun wrote:

Hi there,

> When I visit  server2 using ip 192.168.0.10, the server will give me
> response of server1.

http://nginx.org/en/docs/http/request_processing.html

> Is there anyway to resolve this?

Probably simplest is to list all of the desired listen addresses in each
server{} block.

(I don't know if there's a sensible way to have server1 just reject
any incoming requests to the "wrong" addresses -- if so, that might be
an alternative.)

  f
--
Francis Daly        francis@daoine.org
Posted by Jonathan Matthews (Guest)
on 2012-12-11 13:23
(Received via mailing list)
On 11 December 2012 11:54, adam sun <lists@ruby-forum.com> wrote:
> server {
>       server_name 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
Please log in before posting. Registration is free and takes only a minute.
Existing account (Switch to SSL-encrypted connection)
NEW: Do you have a Google/GoogleMail or Yahoo account? No registration required!
Log in with Google account | Log in with Yahoo account
No account? Register here.