Search code examples
httphttpslighttpd

getting a refused connection error when trying to do HTTP->HTTPS in lighttpd.config


I was looking at how to redirect from HTTP to HTTPS on the Lighttpd website, and it looked really easy. (https://redmine.lighttpd.net/projects/1/wiki/HowToRedirectHttpToHttps)

$HTTP["scheme"] == "http" {
  # capture vhost name with regex conditiona -> %0 in redirect pattern
  # must be the most inner block to the redirect rule
  $HTTP["host"] =~ ".*" {
    url.redirect = (".*" => "https://%0$0")
  }
}

but it doesn't reroute at all.

I have been trying to access the websites by way of www.test.com, http://www.test.com, and http://test.com but it doesnt seem to work.

It just says: ERR Connection Refused. I have confirmed that the website works in http and https without this code, but when doing this, it doesnt seem to work.

I would like to understand it more since I will have a bunch of other domains routing through here eventually.

I have also tried more specific calls as well which didnt work:

$HTTP["scheme"] == "http" {
  # capture vhost name with regex conditiona -> %0 in redirect pattern
  # must be the most inner block to the redirect rule
  $HTTP["host"] =~ "www.test.com" {
    url.redirect = (".*" => "https://%0$0")
  }
}

Solution

  • Doing the above code in the question is actually valid. The issue is, as pointed out by @Gstrauss is that in order to have redirect capabilities, you need to make sure that module is actually enabled. I looked into the modules.conf file and noticed it was not enabled.

    Upon enabling the mod_redirect, and restarting the server, no matter if i went to HTTP or HTTPS version of my site, it would forward me to the HTTPS version of the site.