httpd-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dgau...@hotwired.com (Dean Gaudet)
Subject Re: more problems with Host:'s
Date Mon, 30 Sep 1996 07:28:27 GMT
Argh this code is a mess.  I'm looking at check_hostalias, which appears
to have been modified between 1.1.1 and 1.2:

*** check_hostalias.111	Mon Sep 30 00:13:46 1996
--- check_hostalias.12	Mon Sep 30 00:14:12 1996
***************
*** 1,13 ****
! void check_hostalias (request_rec *r) {
    char *host = getword(r->pool, &r->hostname, ':');	/* Get rid of port */
!   int port = (*r->hostname) ? atoi(r->hostname) : 0;
    server_rec *s;
  
    if (port && (port != r->server->port))
      return;
  
!   if ((host[strlen(host)-1]) == '.') {
!     host[strlen(host)-1] = '\0';
    }
  
    r->hostname = host;
--- 1,15 ----
! static void check_hostalias (request_rec *r) {
    char *host = getword(r->pool, &r->hostname, ':');	/* Get rid of port */
!   int port = (*r->hostname) ? atoi(r->hostname) : 80;
    server_rec *s;
+   int l;
  
    if (port && (port != r->server->port))
      return;
  
!   l = strlen(host)-1;
!   if ((host[l]) == '.') {
!     host[l] = '\0';
    }
  
    r->hostname = host;
***************
*** 15,22 ****
    for (s = r->server->next; s; s = s->next) {
      char *names = s->names;
      
!     if ((!strcasecmp(host, s->server_hostname)) &&
! 	(!port || (port == s->port))) {
        r->server = r->connection->server = s;
        if (r->hostlen && !strncmp(r->uri, "http://", 7)) {
  	r->uri += r->hostlen;
--- 17,23 ----
    for (s = r->server->next; s; s = s->next) {
      char *names = s->names;
      
!     if ((!strcasecmp(host, s->server_hostname)) && (port == s->port)) {
        r->server = r->connection->server = s;
        if (r->hostlen && !strncmp(r->uri, "http://", 7)) {
  	r->uri += r->hostlen;

Notice that the default for the local variable ports was changed from
0 to 80.  But then the if statement:

    if (port && (port != r->server->port))
      return;

Is always going to return since r->server->port defaults to 0 when
no port is specified when configuring a virtualhost.

Unfortunately this changed occured during Alexei's huge HTTP/1.1 commit
(revision 1.30 of http_protocol.c).

What happens when you put Port 80 in each of your virtualhosts?

Dean

P.S. check_fulluri() will become a performance hog in the future if
all requests use "GET http://host/path/ HTTP/x.y" -- it will do a 
DNS lookup on every hit to find out if host matches its ip.  See
read_request_line().  It is a hog now on proxies since all requests
are of that form.

In article <hot.mailing-lists.new-httpd-Pine.SGI.3.93.960929223103.8182E-100000@fully.organic.com>,
Brian Behlendorf  <new-httpd@hyperreal.com> wrote:
>
>Randy's patch (r->server->next ==> r->server) didn't change a thing.  to "fix
>it" I had to place the vhost segment for what I was calling the "default"
>server at the end.
>
>Here's the relevant sections from my httpd.conf file.  Hyperreal's primary
>address is 204.152.144.36.
>
>  Port 8O
>  ServerName www.hyperreal.com
>  DocumentRoot /export/pub
>
><<These are the configs I am presuming would apply if a request to
>204.152.144.36 came without a Host: header!!>>
>
>  <VirtualHost 204.152.144.36>
>  ServerName www.grooveneedle.com
>  .....
>  </VirtualHost>
>
>  <VirtualHost 204.152.144.36>
>  ServerName dev.apache.org
>  ...
>  </VirtualHost>
>
>  <VirtualHost 204.152.144.36>
>  ServerName www.hyperreal.com
>  Redirect /axiom http://www.hyperreal.com/music/labels/axiom
>  ...(lots of stuff I want to ONLY apply to www.hyperreal.com)...
>  </VirtualHost>
>
>  <VirtualHost 204.152.144.38>
>  ServerName www.apache.org
>  ....
>  </VirtualHost>
>
>   etc...
>
>In order for www.hyperreal.com to come up as the host for requests without a
>Host: header, it must be the *last* of the 204.152.144.36 vhosts.  Previously I
>had it as the *first*, and accesses were defaulting to dev.apache.org's vhost
>section.  This is a change that happened recently, as in the last few weeks at
>the most.
>
>Now, THIS is where it gets interesting, and what is a real BUG compared to
>just being a confusing aspect of the current config situation. Let's say I 
>move the vhost segment for www.apache.org in between www.grooveneedle.com and
>dev.apache.org.  When I do that, EVERY request for dev.apache.org and
>www.hyperreal.com get shunted to www.grooveneedle.com.  If I move the vhost
>segment for www.apache.org in between dev.apache.org and www.hyperreal.com, the
>www.grooveneedle.com and dev.apache.org work fine, but www.hyperreal.com gets
>shunted to dev.apache.org.  It appears that only name-vhost segments before the 
>first IP-vhost segment are matched!
>
>It looks like the ONLY acceptible config file format is
> 
>  VirtualHost name-vhost1
>  VH name-vhost2
>  ....
>  VH default-server
>  VH IP-vhost1
>  VH IP-vhost2
>
>Etc.  Anyone have evidence to the contrary?  Does someone know the code well
>enough in this area to find the cause?
>
>On 29 Sep 1996, Dean Gaudet wrote:
>> It doesn't seem screwy to me (mind you, I'm looking at 1.1.1 code):
>> 
>> www.hyperreal.com	IN A 204.152.144.36
>> www.grooveneedle.com	IN A 204.152.144.36
>> 
>> <virtualhost>s are stacked, so the last in the file is the first
>> match found.  Unless the request has something to differentiate it --
>> which "GET / HTTP/1.0" doesn't -- you get the first match found in
>> find_virtual_server.
>
>Okay, this is the crux of my misunderstanding/problem statement.  I guess
>nowhere is the logic "if there's no Host header, default to the 'main' server
>on that IP number", and if that's the server's main IP number ("Port", outside
>of <vhost> segments), then it should bind to the same DocumentRoot which sits
>outside the <vhost> segments as well.  In fact the logic should check that the
>vhost segment with ServerName set to the same as ServerName set outside any
><vhost> segment is the "default" server; presumably that was put there (as I
>did, and I know lots others do) to allow for certain configs to be scoped
>locally to the main server, not globally to all servers.
>
>> Anyhow, since check_serverpath() searches from last <virtualhost> to first,
>> if you put "ServerPath /" into hyperreal's <virtualhost> section it will
>> become the default.
>
>Or rearrange the order, as I did do.  Neither this or the above suggestion are
>intuitive, nor were they required before sometime in the last two weeks.
>
>	Brian
>
>--=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=--
>brian@organic.com  www.apache.org  hyperreal.com  http://www.organic.com/JOBS
>



Mime
View raw message