[UserError] reverse proxy Host header
Added by sl5 about 16 years ago
When used as a reverse proxy, lighttpd omits the "Host" header from the request it issues and adds "X-Host" instead. How do you get it to leave the Host header as-is?
My reverse proxy conf snippet looks like:
$HTTP["host"] == "example.com" { proxy.server = ( "" => ( ( "host" => "10.0.0.5", "port" => 80 ) ) ) }
Replies (7)
RE: reverse proxy Host header - Added by nitrox about 16 years ago
The lighty server (or reverse-proxy) is the "new" host for the request to the backend. So the x-host header is the only way to transport the host information from lighty to the backend (depending on the app running there you might use that information instead?). Its just as with the original IP from the requesting host.
But someone might correct me on this...
RE: reverse proxy Host header - Added by sl5 about 16 years ago
I need to correct this: the lighttpd reverse proxy is indeed sending the right Host header to the backend, the problem is that lighttpd is sending an HTTP/1.0 request, not an HTTP/1.1 request. I guess that's what's making the backend (apache) ignore the Host header value.
So my new question is how do I make lighttpd (as a reverse proxy) speak HTTP/1.1 to the backend instead of 1.0?
I see server.protocol-http11 in the documentation, but that looks like something unrelated (and is enabled by default and not otherwise specified in my conf file).
RE: RE: reverse proxy Host header - Added by roytam1 over 8 years ago
I wonder if I can add custom header(maybe using mod_setenv?) in proxy.server block?
RE: reverse proxy Host header - Added by gstrauss over 8 years ago
lighttpd mod_proxy sends HTTP/1.0 requests and does send a Host header, if one is provided in the request from the client.
As for setting request headers, yes, that is one of the things mod_setenv is designed and documented to do.
https://redmine.lighttpd.net/projects/lighttpd/wiki/Docs_ModSetenv
RE: reverse proxy Host header - Added by roytam1 over 8 years ago
gstrauss wrote:
lighttpd mod_proxy sends HTTP/1.0 requests and does send a Host header, if one is provided in the request from the client.
As for setting request headers, yes, that is one of the things mod_setenv is designed and documented to do.
https://redmine.lighttpd.net/projects/lighttpd/wiki/Docs_ModSetenv
I tried but maybe I put it in wrong place?
I got: Starting lighttpd: 2016-09-15 08:39:53: (configfile.c.1051) source: /etc/lighttpd/lighttpd.conf line: 523 pos: 55 parser failed somehow near here: $
$HTTP["url"] =~ "^/internalsite/" { setenv.add-request-header = ( "X-Orig-URL" => $HTTP["url"] ); proxy.server = ( "" => ( "host" => ( "host" => "127.0.0.1", "port" => 65082 ) ) ) }
RE: reverse proxy Host header - Added by gstrauss over 8 years ago
2016-09-15 08:39:53: (configfile.c.1051) source: /etc/lighttpd/lighttpd.conf line: 523 pos: 55 parser failed somehow near here: $
Check the syntax of line 523, as indicated in the error message. You provided no line numbers above.
setenv.add-request-header = ( "X-Orig-URL" => $HTTP["url"] );
$HTTP["url"] is not a valid token for setenv.add-request-header (and, for that matter, is not valid anywhere other than a lighttpd condition statement)
To set an arbitrary value, you might look at using mod_magnet and writing a one-line lua script to add the request header.
https://redmine.lighttpd.net/projects/lighttpd/wiki/Docs_ModMagnet
https://redmine.lighttpd.net/projects/lighttpd/wiki/AbsoLUAtion
RE: [UserError] reverse proxy Host header - Added by gstrauss about 8 years ago
@sl5 wrote:
the lighttpd reverse proxy is indeed sending the right Host header to the backend, ...
lighttpd sends Host header to backend if one is provided in the request from the client.
...the problem is that lighttpd is sending an HTTP/1.0 request, not an HTTP/1.1 request. I guess that's what's making the backend (apache) ignore the Host header value.
No, that's not it. Something must be amiss in your scripts running behind the backend.
@roytam1: pig-pilled into this ticket with a tangential question.
Use Docs_ModMagnet to set arbitrary values in request headers.
For the example you gave, setting X-Orig-Uri is not needed. When acting as a reverse proxy, the URL-path sent in the request to the backend is equivalent to $HTTP["url"] unless the request has been modified, e.g. by mod_rewrite.