Lighttpd下的https强制跳转

考虑到以后可能会出现的敏感内容,于是申请并且安装了个免费的startssl的证书,然后~打算看看怎么才能强制使用ssl连接。。。

以下内容摘自:http://redmine.lighttpd.net/projects/1/wiki/HowToRedirectHttpToHttps

 

How to redirect HTTP requests to HTTPS

Since 1.4.19 the following should work. For older versions check the history of this page… or just update, srsly.

Example 1 – redirect everything

$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")
    }
}

Example 2 – specific url

$HTTP["scheme"] == "http" {
    $HTTP["host"] =~ ".*" {
        url.redirect = ("^/phpmyadmin/.*" => "https://%0$0")
    }
}

Example 3 – only for specific vhost and url

$HTTP["scheme"] == "http" {
    $HTTP["host"] == "sth.example.com" {
            url.redirect = ("^/phpmyadmin/.*" => "https://sth.example.com$0")
    }
}

Further stuff

Also works the other way round (https -> http) with if $HTTP["scheme"] == "https"

发表评论

电子邮件地址不会被公开。 必填项已用*标注

此站点使用Akismet来减少垃圾评论。了解我们如何处理您的评论数据