Welcome! Log In Create A New Profile

Advanced

Re: virtualhosts and listen (Listen to all, handle some)

Maxim Dounin
March 10, 2011 04:42AM
Hello!

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

> 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;
> }

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 Dounin

_______________________________________________
nginx mailing list
nginx@nginx.org
http://nginx.org/mailman/listinfo/nginx
Subject Author Posted

virtualhosts and listen (Listen to all, handle some)

pepejose March 10, 2011 03:38AM

Re: virtualhosts and listen (Listen to all, handle some)

pepejose March 10, 2011 04:24AM

Re: virtualhosts and listen (Listen to all, handle some)

Maxim Dounin March 10, 2011 04:42AM

Re: virtualhosts and listen (Listen to all, handle some)

pepejose March 10, 2011 04:55AM



Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 171
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready