在 lighttpd.config 中尝试执行 HTTP->HTTPS 时收到拒绝连接错误

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

我正在研究如何在 Lighttpd 网站上从 HTTP 重定向到 HTTPS,看起来非常简单。 (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[=11=]")
  }
}

但它根本没有重新路由。

我一直在尝试通过 www.test.comhttp://www.test.com, and http://test.com 访问网站,但没有成功似乎有效。

它只是说:ERR 连接被拒绝。我已经确认该网站在没有此代码的情况下可以在 http 和 https 中运行,但是在执行此操作时,它似乎不起作用。

我想更多地了解它,因为我最终会有一堆其他域路由到这里。

我也尝试了更具体的调用,但没有用:

$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[=12=]")
  }
}

做题中上面的代码其实是有效的。问题是,正如@Gstrauss 所指出的那样,为了具有重定向功能,您需要确保实际启用了该模块。我查看了 modules.conf 文件,发现它没有启用。

启用 mod_redirect 并重新启动服务器后,无论我访问网站的 HTTP 还是 HTTPS 版本,它都会将我转到 HTTPS网站版本。