Virtualhosts and listen (Listen to all, handle some)

hello (sorry for my bad english)

in the following example, nginx do bind on all interfaces because exists
a “listen *: 80” right?

OK, so I want to do the following, nginx listens on all interfaces
(localhost, LAN and Internet) but some virtualhost only respond to some
interfaces.

The problem I have is that requests do not process the block server as
it should.

www.site.com respond forbidden 403 on block with server_name phpmyadmin,
why?

I’m doing wrong?

server {
listen *:80 default_server;
server_name _;
return 444;
}

server {
listen 192.168.1.1:80;
server_name phpmyadmin;
}

server {
listen *:80;
server_name www.site.com;
}

server {
listen 127.0.0.1:80;
server_name bots;
}

Posted at Nginx Forum:
http://forum.nginx.org/read.php?2,181900,181900#msg-181900

This makes it valid? why wildcard *: 80 not working properly?
thanks!!!

server {
listen 127.0.0.1:80 default_server;
listen 192.168.1.1:80 default_server;
listen public_ip:80 default_server;

server_name _;
return 444;
}

server {
listen 192.168.1.1:80;

server_name phpmyadmin;
}

server {
listen 127.0.0.1:80;
listen 192.168.1.1:80;
listen public_ip:80;

server_name www.site.com;
}

server {
listen 127.0.0.1:80;

server_name bots;
}

Posted at Nginx Forum:
http://forum.nginx.org/read.php?2,181900,181907#msg-181907

Hello!

On Thu, Mar 10, 2011 at 03:38:28AM -0500, pepejose wrote:

it should.
}

server {
listen 127.0.0.1:80;
server_name bots;
}

By defining listen on separate ip you exclude it from matching
on servers with listen *, very much like what happens with two
separate listening sockets.

I.e. with your config only “phpmyadmin” will respond on
192.168.1.1:80, and only “bots” will respond on 127.0.0.1:80.

If you want www.site.com to handle requests on 192.168.1.1:80 as
well - you have to explicitly include this listen into
www.site.com server, i.e. use

server {
    listen        *:80;
    listen        192.168.1.1:80;
    server_name   www.site.com;
}

The same applies to other servers/listens.

Maxim D.

thanks for answering maxim.

then it not makes sense to use *: 80 in this case??

the following is correct?

THANK YOU!

DEFAULT SERVER FOR ALL NETWORK INTERFACES

server {
listen 127.0.0.1:80 default_server;
listen 192.168.1.1:80 default_server;
listen public_ip:80 default_server;

server_name _;
return 444;
}

HANDLE ONLY LAN

server {
listen 192.168.1.1:80;

server_name phpmyadmin;
}

HANDLE LOCALHOST LAN AND INTERNET##

server {
listen 127.0.0.1:80;
listen 192.168.1.1:80;
listen public_ip:80;

server_name www.site.com;
}

HANDLE ONLY LOCALHOST##

server {
listen 127.0.0.1:80;

server_name bots;
}

Posted at Nginx Forum:
http://forum.nginx.org/read.php?2,181900,181911#msg-181911

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs