I have an instance of lighttpd 1.4.35 listening for https traffic and reverse-proxying it to a back-end server. I.e.,
.----------. .----------.
client ---https--> | lighttpd | ---http--> | back-end |
<--https--- | | <--http--- | server |
`----------' `----------'
When I do an HTTP post to a proxied page (over https), the back-end server is returning a Location header with http
instead of https
.
Location: http://lighttpd_url/some_page.htm
Is there a way lighttpd can rewrite the URL in the location header? I see in lighttpd 1.5.x, proxy-core has a rewrite-response
directive, and I guess this is what it would look like:
proxy-core.rewrite-response = (
"Location" => ( "^http://xyz/(.*)" => "https://xyz/$1" ),
)
But how do I rewrite the Location
header in lighttpd 1.4.x?
Best Answer
As of 1.4.35, mod_proxy doesn't let you modify response headers. But I really needed the simple functionality of changing
Location
response headers from http to https, so I hacked it into mod_proxy.c.Here is the patch in case it's useful to anyone else. After applying this patch and then rebuilding and installing from source, you can add
proxy.force_https_location = 1
to your config file to enable the feature globally.