Project

General

Profile

[Solved] re-direct non-localhost http to https

Added by jello almost 4 years ago

Hello,

I'd like to redirect all http traffic on my publicly accessible interface(s) to https. I've seen https://redmine.lighttpd.net/projects/lighttpd/wiki/HowToRedirectHttpToHttps and I'm trying to tweak it to do what I want, but I can't seem to make it happy.

I've tried the following:

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

Any ideas?


Replies (3)

RE: re-direct non-localhost http to https - Added by jello almost 4 years ago

Answering my own question, the following seems to work for both IPv4 & IPv6:

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

RE: re-direct non-localhost http to https - Added by gstrauss almost 4 years ago

$HTTP["scheme"] == "http" {
    $SERVER["socket"] != "127.0.0.1:80" {
      $SERVER["socket"] != "[::1]:80" {
        url.redirect = ("" => "https://${url.authority}${url.path}${qsa}")
      }
    }
}

RE: [Solved] re-direct non-localhost http to https - Added by gstrauss almost 4 years ago

Improved solution posted to https://redmine.lighttpd.net/boards/2/topics/9177?r=9178#message-9178

$HTTP["scheme"] == "http" {
    $HTTP["remote-ip"] != "127.0.0.1" {
      $HTTP["remote-ip"] != "[::1]" {
        url.redirect = ("" => "https://${url.authority}${url.path}${qsa}")
      }
    }
}

    (1-3/3)