Return-Path: Delivered-To: apmail-apache-cvs-archive@apache.org Received: (qmail 76116 invoked by uid 500); 12 Sep 2000 16:32:40 -0000 Mailing-List: contact apache-cvs-help@apache.org; run by ezmlm Precedence: bulk X-No-Archive: yes Reply-To: new-httpd@apache.org list-help: list-unsubscribe: list-post: Delivered-To: mailing list apache-cvs@apache.org Received: (qmail 76099 invoked by uid 500); 12 Sep 2000 16:32:39 -0000 Delivered-To: apmail-apache-1.3-cvs@apache.org Date: 12 Sep 2000 16:32:38 -0000 Message-ID: <20000912163238.76093.qmail@locus.apache.org> From: fanf@locus.apache.org To: apache-1.3-cvs@apache.org Subject: cvs commit: apache-1.3/src/main http_vhost.c fanf 00/09/12 09:32:38 Modified: htdocs/manual/mod core.html htdocs/manual/vhosts details.html examples.html name-based.html src CHANGES src/main http_vhost.c Log: This commit adds support for purely name-based virtual hosting that does not require any IP addresses in httpd.conf and which disregards the local IP address of any connections. This will be particularly appreciated by people running little servers on machines with dynamically configured IP addresses, and by people wishing to use identical httpd.conf files on all the machines in a load-balanced cluster. The configuration syntax is: NameVirtualHost * ServerName my.friend.has.a.silly.vanitydomain.org DocumentRoot /usr/local/apache/docs1 ServerName but.easier.to.spell.than.my.vanitydomain.org DocumentRoot /usr/local/apache/docs2 The implementation is a straightforward extension of what is there already although the patch is made somewhat larger by the need to avoid duplicate code for normal and wildcarded NameVirtualHosts. PR: 5595, 4455 Revision Changes Path 1.171 +8 -0 httpd-docs-1.3/htdocs/manual/mod/core.html Index: core.html =================================================================== RCS file: /home/cvs/httpd-docs-1.3/htdocs/manual/mod/core.html,v retrieving revision 1.170 retrieving revision 1.171 diff -u -u -r1.170 -r1.171 --- core.html 2000/09/12 02:29:12 1.170 +++ core.html 2000/09/12 16:32:35 1.171 @@ -2146,6 +2146,14 @@
NameVirtualHost 111.22.33.44:8080
+In Apache 1.3.13 and greater you can specify a * for the +addr. This creates a wildcard NameVirtualHost which will +match connections to any address that isn't configured with a more +specific NameVirtualHost directive or +<VirtualHost> section. This is useful +if you want only name-based virtual hosts and you don't want to +hard-code the server's IP address into the configuration file.

+ See also: Apache Virtual Host documentation


1.11 +9 -1 httpd-docs-1.3/htdocs/manual/vhosts/details.html Index: details.html =================================================================== RCS file: /home/cvs/httpd-docs-1.3/htdocs/manual/vhosts/details.html,v retrieving revision 1.10 retrieving revision 1.11 diff -u -u -r1.10 -r1.11 --- details.html 1999/02/14 14:26:49 1.10 +++ details.html 2000/09/12 16:32:35 1.11 @@ -69,7 +69,8 @@

Unless a NameVirtualHost directive is used for a specific IP address the first vhost with -that address is treated as an IP-based vhost. +that address is treated as an IP-based vhost. In 1.3.13 and later that +includes the IP address *.

If name-based vhosts should be used a NameVirtualHost directive must appear with the IP address set to be used for the @@ -202,6 +203,11 @@ matching _default_ vhost the request is served from the main_server. +

In Apache 1.3.13 and later, if the IP address is not found in the +hash table then the match against the port number may also result in +an entry corresponding to a NameVirtualHost *, which is +subsequently handled like other name-based vhosts. +

If the lookup succeeded (a corresponding list for the IP address was found) the next step is to decide if we have to deal with an IP-based or a name-base vhost. @@ -309,6 +315,8 @@ _default_ vhost which is your standard Port by default. A wildcard port can be specified (i.e., _default_:*) to catch requests to any available port. + In Apache 1.3.13 and later this also applies to + NameVirtualHost * vhosts.

  • The main_server is only used to serve a request if the IP address 1.8 +47 -0 httpd-docs-1.3/htdocs/manual/vhosts/examples.html Index: examples.html =================================================================== RCS file: /home/cvs/httpd-docs-1.3/htdocs/manual/vhosts/examples.html,v retrieving revision 1.7 retrieving revision 1.8 diff -u -u -r1.7 -r1.8 --- examples.html 2000/09/12 02:29:17 1.7 +++ examples.html 2000/09/12 16:32:36 1.8 @@ -30,6 +30,7 @@
  • Using _default_ vhosts
  • Migrating a named-based vhost to an IP-based vhost
  • Using the ServerPath directive +
  • Purely name-based vhosting
    @@ -540,6 +541,52 @@ +

    Purely name-based vhosting

    + +
      + +
    • Compatibility: + This feature was added in Apache 1.3.13. + +
    • Setup: + The server machine has an IP address + which resolves to the name server.domain.tld. + There are two aliases (CNAMEs) www.domain.tld and + www.sub.domain.tld for the address server.domain.tld. +

      + Server configuration: + +

        +    ...
        +    Port 80
        +    ServerName server.domain.tld
        +
        +    NameVirtualHost *
        +
        +    <VirtualHost *>
        +    DocumentRoot /www/domain
        +    ServerName www.domain.tld
        +    ...
        +    </VirtualHost>
        +    
        +    <VirtualHost *>
        +    DocumentRoot /www/subdomain
        +    ServerName www.sub.domain.tld
        +    ...
        +    </VirtualHost> 
        +    
      + There are no unspecified + addresses/ports, therefore the main server serves + no requests. Due to the fact + that www.domain.tld has the highest priority + it can be seen as the default or + primary server. +
      +

      + +

    + +
  • Setup: 1.12 +9 -0 httpd-docs-1.3/htdocs/manual/vhosts/name-based.html Index: name-based.html =================================================================== RCS file: /home/cvs/httpd-docs-1.3/htdocs/manual/vhosts/name-based.html,v retrieving revision 1.11 retrieving revision 1.12 diff -u -u -r1.11 -r1.12 --- name-based.html 2000/09/09 17:59:42 1.11 +++ name-based.html 2000/09/12 16:32:36 1.12 @@ -84,6 +84,15 @@ In other words, you should add a <VirtualHost> section for every server (hostname) you want to maintain on your server. +

    In Apache 1.3.13 and later you can specify the +NameVirtualHost IP address as the wildcard * +which matches any IP address not covered by more specific virtual +host directive(s). This is useful for configuring a server whose IP +address you do not know in advance, e.g. because it has a dynamically +configured IP address or because it is part of a load-balanced cluster +in which every machine shares the same configuration file. +

    +

    Additionally, many servers may wish to be accessible by more than one name. For example, the example server might want to be accessible as domain.tld, or www2.domain.tld, assuming 1.1573 +6 -0 apache-1.3/src/CHANGES Index: CHANGES =================================================================== RCS file: /home/cvs/apache-1.3/src/CHANGES,v retrieving revision 1.1572 retrieving revision 1.1573 diff -u -u -r1.1572 -r1.1573 --- CHANGES 2000/09/12 15:16:18 1.1572 +++ CHANGES 2000/09/12 16:32:36 1.1573 @@ -1,5 +1,11 @@ Changes with Apache 1.3.13 + *) NameVirtualHost can now take "*" as an argument instead of + an IP address. This allows you to create a purely name-based + virtual hosting server that does not have any IP addresses in + the configuration file and which ignores the local address + of any connections. PR #5595, PR #4455 [Tony Finch] + *) Fix processing/merging of Remove* MIME directives. PR #5597 [Sander van Zoest ] 1.19 +140 -112 apache-1.3/src/main/http_vhost.c Index: http_vhost.c =================================================================== RCS file: /home/cvs/apache-1.3/src/main/http_vhost.c,v retrieving revision 1.18 retrieving revision 1.19 diff -u -u -r1.18 -r1.19 --- http_vhost.c 2000/01/16 20:59:59 1.18 +++ http_vhost.c 2000/09/12 16:32:38 1.19 @@ -409,64 +409,122 @@ return NULL; } +static void dump_a_vhost(FILE *f, ipaddr_chain *ic) +{ + name_chain *nc; + int len; + char buf[MAX_STRING_LEN]; + + if (ic->sar->host_addr.s_addr == DEFAULT_VHOST_ADDR) { + len = ap_snprintf(buf, sizeof(buf), "_default_:%u", + ic->sar->host_port); + } + else if (ic->sar->host_addr.s_addr == INADDR_ANY) { + len = ap_snprintf(buf, sizeof(buf), "*:%u", + ic->sar->host_port); + } + else { + len = ap_snprintf(buf, sizeof(buf), "%pA:%u", + &ic->sar->host_addr, ic->sar->host_port); + } + if (ic->sar->host_port == 0) { + buf[len-1] = '*'; + } + if (ic->names == NULL) { + fprintf(f, "%-22s %s (%s:%u)\n", buf, ic->server->server_hostname, + ic->server->defn_name, ic->server->defn_line_number); + return; + } + fprintf(f, "%-22s is a NameVirtualHost\n" + "%22s default server %s (%s:%u)\n", + buf, "", ic->server->server_hostname, + ic->server->defn_name, ic->server->defn_line_number); + for (nc = ic->names; nc; nc = nc->next) { + if (nc->sar->host_port) { + fprintf(f, "%22s port %u ", "", nc->sar->host_port); + } + else { + fprintf(f, "%22s port * ", ""); + } + fprintf(f, "namevhost %s (%s:%u)\n", nc->server->server_hostname, + nc->server->defn_name, nc->server->defn_line_number); + } +} static void dump_vhost_config(FILE *f) { - int i; ipaddr_chain *ic; - name_chain *nc; - char buf[MAX_STRING_LEN]; + int i; fprintf(f, "VirtualHost configuration:\n"); for (i = 0; i < IPHASH_TABLE_SIZE; ++i) { for (ic = iphash_table[i]; ic; ic = ic->next) { - if (ic->sar->host_port == 0) { - ap_snprintf(buf, sizeof(buf), "%pA:*", &ic->sar->host_addr); - } - else { - ap_snprintf(buf, sizeof(buf), "%pA:%u", &ic->sar->host_addr, - ic->sar->host_port); - } - if (ic->names == NULL) { - fprintf(f, "%-22s %s (%s:%u)\n", buf, - ic->server->server_hostname, ic->server->defn_name, - ic->server->defn_line_number); - continue; - } - fprintf(f, "%-22s is a NameVirtualHost\n" - "%22s default server %s (%s:%u)\n", - buf, "", ic->server->server_hostname, - ic->server->defn_name, ic->server->defn_line_number); - for (nc = ic->names; nc; nc = nc->next) { - if (nc->sar->host_port) { - fprintf(f, "%22s port %u ", "", nc->sar->host_port); - } - else { - fprintf(f, "%22s port * ", ""); - } - fprintf(f, "namevhost %s (%s:%u)\n", - nc->server->server_hostname, - nc->server->defn_name, - nc->server->defn_line_number); - } + dump_a_vhost(f, ic); } } if (default_list) { - fprintf(f, "_default_ servers:\n"); + fprintf(f, "wildcard NameVirtualHosts and _default_ servers:\n"); for (ic = default_list; ic; ic = ic->next) { - if (ic->sar->host_port == 0) { - fprintf(f, "port * "); - } - else { - fprintf(f, "port %u ", ic->sar->host_port); - } - fprintf(f, "server %s (%s:%u)\n", - ic->server->server_hostname, ic->server->defn_name, - ic->server->defn_line_number); + dump_a_vhost(f, ic); } } } +/* + * Helper functions for ap_fini_vhost_config() + */ +static int add_name_vhost_config(pool *p, server_rec *main_s, server_rec *s, + server_addr_rec *sar, ipaddr_chain *ic) +{ + /* the first time we encounter a NameVirtualHost address + * ic->server will be NULL, on subsequent encounters + * ic->names will be non-NULL. + */ + if (ic->names || ic->server == NULL) { + name_chain *nc = new_name_chain(p, s, sar); + nc->next = ic->names; + ic->names = nc; + ic->server = s; + if (sar->host_port != ic->sar->host_port) { + /* one of the two is a * port, the other isn't */ + ap_log_error(APLOG_MARK, APLOG_NOERRNO|APLOG_ERR, main_s, + "VirtualHost %s:%u -- mixing * " + "ports and non-* ports with " + "a NameVirtualHost address is not supported," + " proceeding with undefined results", + sar->virthost, sar->host_port); + } + return 1; + } + else { + /* IP-based vhosts are handled by the caller */ + return 0; + } +} + +static void remove_unused_name_vhosts(server_rec *main_s, ipaddr_chain **pic) +{ + while (*pic) { + ipaddr_chain *ic = *pic; + + if (ic->server == NULL) { + ap_log_error(APLOG_MARK, APLOG_NOERRNO|APLOG_WARNING, main_s, + "NameVirtualHost %s:%u has no VirtualHosts", + ic->sar->virthost, ic->sar->host_port); + *pic = ic->next; + } + else if (ic->names == NULL) { + /* if server != NULL and names == NULL then we're done + * looking at NameVirtualHosts + */ + break; + } + else { + pic = &ic->next; + } + } +} + /* compile the tables and such we need to do the run-time vhost lookups */ void ap_fini_vhost_config(pool *p, server_rec *main_s) { @@ -497,13 +555,22 @@ */ for (sar = name_vhost_list; sar; sar = sar->next) { unsigned bucket = hash_inaddr(sar->host_addr.s_addr); - ipaddr_chain *new = new_ipaddr_chain(p, NULL, sar); + ipaddr_chain *ic = new_ipaddr_chain(p, NULL, sar); - *iphash_table_tail[bucket] = new; - iphash_table_tail[bucket] = &new->next; - + if (sar->host_addr.s_addr != INADDR_ANY) { + *iphash_table_tail[bucket] = ic; + iphash_table_tail[bucket] = &ic->next; + } + else { + /* A wildcard NameVirtualHost goes on the default_list so + * that it can catch incoming requests on any address. + */ + ic->next = default_list; + default_list = ic; + } /* Notice that what we've done is insert an ipaddr_chain with - * both server and names NULL. Remember that. + * both server and names NULL. This fact is used to spot name- + * based vhosts in add_name_vhost_config(). */ } @@ -520,46 +587,31 @@ if (sar->host_addr.s_addr == DEFAULT_VHOST_ADDR || sar->host_addr.s_addr == INADDR_ANY) { - /* add it to default bucket for each appropriate sar - * since we need to do a port test - */ - ipaddr_chain *other; - - other = find_default_server(sar->host_port); - if (other && other->sar->host_port != 0) { - ap_log_error(APLOG_MARK, APLOG_NOERRNO|APLOG_WARNING, main_s, - "_default_ VirtualHost overlap on port %u," + ic = find_default_server(sar->host_port); + if (!ic || !add_name_vhost_config(p, main_s, s, sar, ic)) { + if (ic && ic->sar->host_port != 0) { + ap_log_error(APLOG_MARK, APLOG_NOERRNO|APLOG_WARNING, + main_s, "_default_ VirtualHost overlap on port %u," " the first has precedence", sar->host_port); + } + ic = new_ipaddr_chain(p, s, sar); + ic->next = default_list; + default_list = ic; } has_default_vhost_addr = 1; - ic = new_ipaddr_chain(p, s, sar); - ic->next = default_list; - default_list = ic; } else { /* see if it matches something we've already got */ ic = find_ipaddr(&sar->host_addr, sar->host_port); - /* the first time we encounter a NameVirtualHost address - * ic->server will be NULL, on subsequent encounters - * ic->names will be non-NULL. - */ - if (ic && (ic->names || ic->server == NULL)) { - name_chain *nc = new_name_chain(p, s, sar); - nc->next = ic->names; - ic->names = nc; - ic->server = s; - if (sar->host_port != ic->sar->host_port) { - /* one of the two is a * port, the other isn't */ - ap_log_error(APLOG_MARK, APLOG_NOERRNO|APLOG_ERR, main_s, - "VirtualHost %s:%u -- mixing * " - "ports and non-* ports with " - "a NameVirtualHost address is not supported," - " proceeding with undefined results", - sar->virthost, sar->host_port); - } + if (!ic) { + unsigned bucket = hash_inaddr(sar->host_addr.s_addr); + + ic = new_ipaddr_chain(p, s, sar); + ic->next = *iphash_table_tail[bucket]; + *iphash_table_tail[bucket] = ic; } - else if (ic) { + else if (!add_name_vhost_config(p, main_s, s, sar, ic)) { ap_log_error(APLOG_MARK, APLOG_NOERRNO|APLOG_WARNING, main_s, "VirtualHost %s:%u overlaps with " "VirtualHost %s:%u, the first has precedence, " @@ -569,13 +621,6 @@ ic->sar = sar; ic->server = s; } - else { - unsigned bucket = hash_inaddr(sar->host_addr.s_addr); - - ic = new_ipaddr_chain(p, s, sar); - ic->next = *iphash_table_tail[bucket]; - *iphash_table_tail[bucket] = ic; - } } } @@ -621,28 +666,9 @@ * hosts associated with them. Lamers. */ for (i = 0; i < IPHASH_TABLE_SIZE; ++i) { - ipaddr_chain **pic = &iphash_table[i]; - - while (*pic) { - ipaddr_chain *ic = *pic; - - if (ic->server == NULL) { - ap_log_error(APLOG_MARK, APLOG_NOERRNO|APLOG_WARNING, main_s, - "NameVirtualHost %s:%u has no VirtualHosts", - ic->sar->virthost, ic->sar->host_port); - *pic = ic->next; - } - else if (ic->names == NULL) { - /* if server != NULL and names == NULL then we're done - * looking at NameVirtualHosts - */ - break; - } - else { - pic = &ic->next; - } - } + remove_unused_name_vhosts(main_s, &iphash_table[i]); } + remove_unused_name_vhosts(main_s, &default_list); #ifdef IPHASH_STATISTICS dump_iphash_statistics(main_s); @@ -933,16 +959,18 @@ return; } - /* There's certainly no name-vhosts with this address, they would have - * been matched above. + /* maybe there's a default server or wildcard name-based vhost + * matching this port */ - conn->vhost_lookup_data = NULL; - - /* maybe there's a default server matching this port */ trav = find_default_server(port); if (trav) { + conn->vhost_lookup_data = trav->names; conn->server = trav->server; + return; } - /* otherwise we're stuck with just the main server */ + /* otherwise we're stuck with just the main server + * and no name-based vhosts + */ + conn->vhost_lookup_data = NULL; }