librelist archives

« back to archive

Host matching

Host matching

From:
Wesley Moore
Date:
2010-10-14 @ 01:51
Hi,
I'm trying to get host matching working but it never matches, are
there any known issues with this? When I make a request via a host
that should match I get the following message from the mongrel2
server:

[ERROR] (src/connection.c:140: errno: Resource temporarily
unavailable) Request for a host we don't have registered: 127.0.0.1

When I load the config (shown below) the matching value isn't inserted
in to the config db. If I change the value in the db manually it works
as I expect.

m2sh load -config test.conf

sqlite> select * from host;
id          server_id   maintenance  name        matching
----------  ----------  -----------  ----------  ----------
1           1           0            localhost   localhost

handler_test = Handler(
  send_ident='558c92aa-1644-4e24-a524-39baad0f8e78',
  send_spec='tcp://127.0.0.1:8988',
  recv_spec='tcp://127.0.0.1:8989', recv_ident='')

weather = Handler(
  send_ident='AA40D395-4CA6-47CD-9D8C-FD4FDF92487E',
  send_spec='tcp://127.0.0.1:7777',
  recv_spec='tcp://127.0.0.1:7778', recv_ident='')

main = Server(
    uuid="f400bf85-4538-4f7a-8908-67e313d515c2",
    access_log="/logs/access.log",
    error_log="/logs/error.log",
    chroot="./",
    default_host="localhost",
    name="test",
    pid_file="/run/mongrel2.pid",
    port=6767,
    hosts = [
        Host(name="localhost", routes={
            '/': handler_test,
            '/weather': weather
        },
        matching="127.0.0.1")
    ]
)

servers = [main]

Environment: mongrel2-1.3, zmq-2.0.9, Mac OS X 10.6.4

Regards,
Wes

Re: [mongrel2] Host matching

From:
Zed A. Shaw
Date:
2010-10-14 @ 06:06
On Thu, Oct 14, 2010 at 12:51:29PM +1100, Wesley Moore wrote:
> Hi,
> I'm trying to get host matching working but it never matches, are
> there any known issues with this? When I make a request via a host
> that should match I get the following message from the mongrel2
> server:
> 
> [ERROR] (src/connection.c:140: errno: Resource temporarily
> unavailable) Request for a host we don't have registered: 127.0.0.1


> m2sh load -config test.conf
> 
> sqlite> select * from host;
> id          server_id   maintenance  name        matching
> ----------  ----------  -----------  ----------  ----------
> 1           1           0            localhost   localhost

Yes, so it matches not the address of the machine but the Host: header
that your browser/client sends.  So if you have localhost as your
hostname, but you connect with curl http://127.0.0.1 then it'll fail
since the Host: header will actually be 127.0.0.1.

First try just curl against http://localhost.  Then you can add both by
doing this:

routes={}
main = Server(
    hosts=[
    Host(name="127.0.0.1", routes=routes)
    Host(name="localhost", routes=routes)
 ]
)

That just sets up two different hosts for the two aliases you want and
then stuffs the routes you have in both of them.


-- 
Zed A. Shaw
http://zedshaw.com/