> OK, I can't figure this out.. help me out here. I want to deal with my > virtual hosts on the heavyweight server. The frontend server should just > be a simple thing that I never have to touch. Matt, you might want to check out this patch to mod_proxy posted to new-httpd by Sam Tregar: "ProxyRewriteHostHeader option to mod_proxy. This configuration directive controls wether mod_proxy will rewrite the Host header or pass it through unchanged. The default is to rewrite, which is the current behavior. This mirrors a setting available in Squid - redirect_rewrites_host_header." I guess this would let you have your virtual host setup only on the backend server. The patch is against the 1.3 CVS tree. -- Eric
Index: src/modules/proxy/mod_proxy.c =================================================================== RCS file: /cvs/apache/apache-1.3/src/modules/proxy/mod_proxy.c,v retrieving revision 1.69 diff -u -r1.69 mod_proxy.c --- mod_proxy.c 2000/03/01 09:13:38 1.69 +++ mod_proxy.c 2000/05/01 01:48:52 @@ -418,6 +418,8 @@ ps->domain = NULL; ps->viaopt = via_off; /* initially backward compatible with 1.3.1 */ ps->viaopt_set = 0; /* 0 means default */ + ps->rewrite_host_header_opt = 1; /* normally always rewrite */ + ps->rewrite_host_header_opt_set = 0; ps->req = 0; ps->req_set = 0; ps->recv_buffer_size = 0; /* this default was left unset for some reason */ @@ -463,6 +465,7 @@ ps->domain = (overrides->domain == NULL) ? base->domain : overrides->domain; ps->viaopt = (overrides->viaopt_set == 0) ? base->viaopt : overrides->viaopt; + ps->rewrite_host_header_opt = (overrides->rewrite_host_header_opt_set == 0) ? +base->rewrite_host_header_opt : overrides->rewrite_host_header_opt; ps->req = (overrides->req_set == 0) ? base->req : overrides->req; ps->recv_buffer_size = (overrides->recv_buffer_size_set == 0) ? base->recv_buffer_size : overrides->recv_buffer_size; @@ -882,6 +885,26 @@ return NULL; } +static const char* + set_rewrite_host_header_opt(cmd_parms *parms, void *dummy, char *arg) +{ + proxy_server_conf *psf = + ap_get_module_config(parms->server->module_config, &proxy_module); + + if (!strcasecmp(arg, "Off")) + psf->rewrite_host_header_opt = 0; + else if (!strcasecmp(arg, "On")) + psf->rewrite_host_header_opt = 1; + else { + return "ProxyRewriteHostHeader must be one of:" + "off | on"; + } + + psf->rewrite_host_header_opt_set = 1; + return NULL; +} + + static const handler_rec proxy_handlers[] = { {"proxy-server", proxy_handler}, @@ -930,6 +953,8 @@ "Force a http cache completion after this percentage is loaded"}, {"ProxyVia", set_via_opt, NULL, RSRC_CONF, TAKE1, "Configure Via: proxy header header to one of: on | off | block | full"}, + {"ProxyRewriteHostHeader", set_rewrite_host_header_opt, NULL, RSRC_CONF, TAKE1, + "Configure handling of Host header. When off the Host header is passed through, +when on the Host header is rewritten based on destination address and pot"}, {NULL} }; Index: src/modules/proxy/mod_proxy.h =================================================================== RCS file: /cvs/apache/apache-1.3/src/modules/proxy/mod_proxy.h,v retrieving revision 1.46 diff -u -r1.46 mod_proxy.h --- mod_proxy.h 2000/01/11 14:13:44 1.46 +++ mod_proxy.h 2000/05/01 01:48:52 @@ -222,6 +222,8 @@ via_full } viaopt; /* how to deal with proxy Via: headers */ char viaopt_set; + char rewrite_host_header_opt; /* wether to rewrite the Host: header */ + char rewrite_host_header_opt_set; size_t recv_buffer_size; char recv_buffer_size_set; } proxy_server_conf; Index: src/modules/proxy/proxy_http.c =================================================================== RCS file: /cvs/apache/apache-1.3/src/modules/proxy/proxy_http.c,v retrieving revision 1.67 diff -u -r1.67 proxy_http.c --- proxy_http.c 2000/02/29 14:24:27 1.67 +++ proxy_http.c 2000/05/01 01:48:52 @@ -172,7 +172,7 @@ const char *strp; char *strp2; const char *err, *desthost; - int i, j, sock, len, backasswards; + int i, j, sock, len, backasswards, sent_host; array_header *reqhdrs_arr; table *resp_hdrs; table_entry *reqhdrs; @@ -307,11 +307,31 @@ ap_hard_timeout("proxy send", r); ap_bvputs(f, r->method, " ", proxyhost ? url : urlptr, " HTTP/1.0" CRLF, - NULL); - if (destportstr != NULL && destport != DEFAULT_HTTP_PORT) - ap_bvputs(f, "Host: ", desthost, ":", destportstr, CRLF, NULL); - else - ap_bvputs(f, "Host: ", desthost, CRLF, NULL); + NULL); + + /* if ProxyRewriteHostHeader is off, look for the incoming Host + header and send it along unchanged */ + sent_host = 0; + if (conf->rewrite_host_header_opt_set && !conf->rewrite_host_header_opt) { + reqhdrs_arr = ap_table_elts(r->headers_in); + reqhdrs = (table_entry *) reqhdrs_arr->elts; + for (i = 0; i < reqhdrs_arr->nelts; i++) { + if (reqhdrs[i].key != NULL && reqhdrs[i].val != NULL && + !strcasecmp(reqhdrs[i].key, "Host")) { + ap_bvputs(f, "Host: ", reqhdrs[i].val, CRLF, NULL); + sent_host = 1; + break; + } + } + } + + /* otherwise, make up a new one based on desthost and destport */ + if (!sent_host) { + if (destportstr != NULL && destport != DEFAULT_HTTP_PORT) + ap_bvputs(f, "Host: ", desthost, ":", destportstr, CRLF, NULL); + else + ap_bvputs(f, "Host: ", desthost, CRLF, NULL); + } if (conf->viaopt == via_block) { /* Block all outgoing Via: headers */