Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am running lighttpd 1.4.31 with ssl support and am having an issue with forcing https on a specific virtualhost. If I disable the redirect line from the following config, it works as expect (http and https both working, but no redirection), but when I enable it, I find the browser gets cause in a loop of 301s. I don't understand why this is happening as to me the redirect should only apply under http. I have mod_redirect loaded in at the top of the config, and one other virtualhost with ssl forced on for some domain...I don't believe that should have any impact. What am I doing wrong in the following config snippet? Please note that I substituted for my domain.

$HTTP["host"] == "" {
    dir-listing.activate = "enable"
    accesslog.filename = "/home/lighttpd/"
    server.document-root = "/home/lighttpd/"
    server.upload-dirs = ("/tmp")
    server.errorlog = "/home/lighttpd/"
    $SERVER["socket"] == ":443" {
            ssl.engine = "enable"
            ssl.pemfile = "/home/lighttpd/"

            $HTTP["url"] =~ "^/shell" { # shellinabox
                    proxy.server = ( "" => ((
                                    "host" => "",
                                    "port" => 4200,
    $HTTP["scheme"] == "http" {
            url.redirect = (".*" => "$0")
share|improve this question

Taking a look at my configuration, which is almost the same as you:

  • I want https
  • and http redirect to https.

I have one more things inside my socket config:

$SERVER["socket"] == ":443" {
        ssl.engine  = "enable"

        # .....

        setenv.add-environment = (
                "HTTPS" => "on"

And my redirect is handled outside the first host, like this:

$HTTP["scheme"] == "http" {
        $HTTP["host"] =~ "" {
                url.redirect = ( "^/(.*)" => "$1" )

And every thing works like a charm.

share|improve this answer
  • I suspect your proxy redirects back to http
  • debug the headers with curl -v
  • debug.log-request-handling = "enable" and check error.log, also see DebugVariables
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.