Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

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 consider this question a duplicate of Lighttpd redirect from to, but that one didn't get enough attention and it's too old).

I'm trying to deploy an app over lighttpd+FastCGI and encrypt all the traffic. It works well if I explicitly use HTTPS in the URL, but as soon I try the redirect from HTTP to HTTPS the URLs the app script name (in this case, is included in the URL, so instead of I get, which triggers a Not Found error.

I tried moving some stuff around, but I can't get how to do the redirect well. Here's the relevant stuff of my lighttpd.conf

$SERVER["socket"] == ":80" {
    $HTTP["host"] =~ "(.*)" {
        url.redirect = (
            "^/(.*)" => "https://%1/$1"

$SERVER["socket"] == ":443" {
    ssl.engine = "enable"
    ssl.pemfile = "certificate.pem"
    ssl.use-sslv2 = "disable"
    ssl.use-sslv3 = "disable"

fastcgi.server = (
    "" => ((
        "socket" => "/tmp/app.socket",
        "bin-path" => "",
        "max-procs" => 1,
        "bin-environment" => (
            "REAL_SCRIPT_NAME" => ""
        "check-local" => "disable"

url.rewrite-once = (
    "^/favicon.ico$" => "/static/assets/favicon.ico",
    "^/static/(.*)$" => "/static/$1",
    "^/(.*)$" => "/$1"
share|improve this question
up vote 0 down vote accepted

rewrite happens before redirect. in your case the solution is to put fastcgi and rewrite in the ssl socket, as you only want it for ssl anyway.

Please don't spawn sockets in /tmp, use a directory dedicated to this where only lighttpd can create files.

share|improve this answer
Thanks for the answer, and for your suggestion. I'm thinking on mount lighttpd over a chroot, but first I need to get the redirection right. I tried your solution, but I got the same behavior :( – Tae Dec 3 '13 at 23:22
Ok, now it works. Thank you very much! – Tae Dec 5 '13 at 0:01

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.