0

I tried to reconfigured my lighttpd to automatically relocate any HTTP requests to HTTPS requests. To do this, I found the following config snipped in the Lighttpd Redmine Wiki:

$HTTP["scheme"] == "http" {
            url.redirect = ("" => "https://${url.authority}${url.path}${qsa}")
}

However, lighttpd does not seem to replace the placeholders. Here is a sample HTTP-Request/Response via telnet (I replaced my Hostname with 'example.org', all the rest is original):

# telnet localhost 80
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
GET / HTTP/1.0
Host: example.org

HTTP/1.0 301 Moved Permanently
Location: https://${url.authority}${url.path}${qsa}
Content-Length: 0
Connection: close
Date: Fri, 11 Sep 2020 12:43:32 GMT
Server: lighttpd/1.4.45

Connection closed by foreign host.

Instead of Location: https://${url.authority}${url.path}${qsa} the line should be Location: https://example.org/.

What's wrong with it? Did I forget to load a module?

Any ideas?

Some parts of my lighttpd.conf:

Since the loading order of modules seems to be important. Here is my current config for that:

server.modules = (
        "mod_expire",
        "mod_access",
        "mod_alias",
        "mod_compress",
        "mod_redirect",
        "mod_rewrite",
        "mod_setenv"
)
# cat /etc/debian_version
9.13

Lighttpd seems to be happy with the configuration file (there is no output for -t or -tt):

# lighttpd -tt -v -f /etc/lighttpd/lighttpd.conf
lighttpd/1.4.45 (ssl) - a light and fast webserver
Build-Date: Jan 14 2017 21:07:19
#

1 Answer 1

2

After some more research, I finally found the solution:

The named placeholders are only supported for lighttpd versions 1.4.50+, but for the older version there is a different solution:

$HTTP["scheme"] == "http" {
        $HTTP["host"] =~ ".*" {
                url.redirect = (".*" => "https://%0$0")
        }
}

This seems to work. %0 is replaced by the full host name (result of last regex match) and $0 is replaced by the whole URI including query string parts. This is exactly what I need...

2
  • 1
    lighttpd 1.4.45 is quite old. I am guessing you are using Debian Stretch. Please consider upgrading to lighttpd 1.4.53 in stretch-backports.
    – gstrauss
    Nov 14, 2020 at 7:33
  • Yes! I'm using Debian Stretch... Looking at stretch-backports is a great idea! Thanks!
    – SDwarfs
    Nov 14, 2020 at 16:12

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .