2

How can I redirect from HTTP to HTTPS with lighthttpd?

There are tons of lighttpd config snippets floating around to make this happen, but so far none of these really worked. Currently I am still playing around with 127.0.0.1, so if anyone has an adequate config in use, that would be great.

My lighttpd version is 1.4.29, OS Arch Linux 64bit

Andrea
  • 1,516
  • 4
  • 17
  • 19
drahnr
  • 370
  • 6
  • 15

2 Answers2

4
$SERVER["socket"] == ":443" {
        ssl.engine = "enable"
        ssl.pemfile = "/path/to/pem/file/unknown.pem"
}


$SERVER["socket"] == ":80" {
        $HTTP["host"] =~ "(.*)" {
                url.redirect = ( "^/(.*)" => "https://%1/$1" )
        }
}

solved it for me.

drahnr
  • 370
  • 6
  • 15
  • 1
    You might want to note that this also requires the use of `mod_redirect`, so adding the line `server.modules += ( "mod_redirect" )` to your config file may be necessary. At least it was for me with lighttpd 1.4.55 – dgnuff Apr 09 '22 at 06:56
1

What I do in this situation is have a small one-page site available through HTTP that contains a single page with a meta refresh tag and possibly an explanation for browsers that have redirects disabled or unsupported for some reason. Create a custom 404 error page that also does the same thing.

The meta tag should then redirect to https://127.0.0.1 or your site's external address when you allow it to be externally reachable.

I would let the page display for 5 seconds using the meta refresh saying "This site is only available through HTTPS. You should be automatically redirected in 5 seconds, if not click here..."

LawrenceC
  • 73,030
  • 15
  • 129
  • 214
  • I get this when using url.redirect: (server.c.1550) WARNING: unknown config-key: url.redirect (ignored). Using lighttpd 1.4.54 – ikwyl6 Jul 15 '19 at 23:24