SSL with Lighttpd

Use SSL encryption on your Lighttpd webserver.

Lighttpd installation
Lighttpd needs to be configured and compiled with SSL enabled:

./configure --with-openssl
make
make install

After lighty has been installed, you can confirm that it has been compiled with ssl enabled:

lighttpd -v

SSL Configuration

mkdir /root/.lighttpdssl
cd /root/.lighttpdssl
openssl req -new -x509 -keyout lighttpd.pem -out lighttpd.pem -days 365 -nodes
chmod 400 lighttpd.pem

Edit /service/lighttpd/root/lighttpd.conf and add:

$SERVER["socket"] == ":443" {
  ssl.engine = "enable"
  ssl.pemfile = "/root/.lighttpdssl/lighttpd.pem"
}

Redirect http to https
How to Redirect HTTP to HTTPS
Enable mod_redirect in your lighttpd.conf:

server.modules = (
"mod_redirect",
)
  • 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")
        }
    }
  • specific url
    $HTTP["scheme"] == "http" {
      $HTTP["host"] =~ ".*" {
        url.redirect = ("^/phpmyadmin/.*" => "https://%0$0")
      }
    }
  • only for specific vhost and url
    $HTTP["scheme"] == "http" {
      $HTTP["host"] == "sth.example.com" {
        url.redirect = ("^/phpmyadmin/.*" => "https://sth.example.com$0" )
      }
    }

Recent Updates

  • 2 years 2 days ago
  • 2 years 2 days ago
  • 2 years 4 days ago
    php 8.x
  • 2 years 6 days ago
    10.6.7
  • 2 years 1 week ago
    Drop Centos 5/6 stuff