log-condition-handling, The hidden feature for debuging

Posted by moo Sun, 02 Apr 2006 05:46:00 GMT

Many features was introduced into lighttpd 1.4.x series to improve config file handling. But there's something left undocumented, yet nice feature, for debuging.

It was originally implemented to debug the new condition caching system internally for developers only.

But i found it nice for user to debug how to condition is matching, seeing the 2 values on both side of the operator, and if they matched. A new patch was commited to make it a bit cleaner for your use.

  1. just add or uncomment: debug.log-condition-handling = "enable" in your configuration.
  2. restart your lighttpd, or start it with sbin/lighttpd -Df lighttpd.conf
  3. request the url, and check the error.log, or stderr in case u haven't specified error.log

./sbin/ligittpd -pf test.conf

config {
  var.PID                      = 25629
  var.CWD                      = "/usr/src/lighttpd/branches/lighttpd-merge-1.4.x"
  server.modules               = ("mod_indexfile", "mod_staticfile")
  server.port                  = 8080
  server.document-root         = "/tmp"
  debug.log-condition-handling = "enable"


  $HTTP["useragent"] =~ "MSIE" {
    # block 1

  } # end of $HTTP["useragent"] =~ "MSIE"
}

./sbin/lighttpd -Df test.conf

2006-04-02 13:40:05: (src/log.c.75) server started 
2006-04-02 13:40:07: (src/response.c.150) run condition 
2006-04-02 13:40:07: (src/configfile-glue.c.404) === start of 1 condition block === 
2006-04-02 13:40:07: (src/configfile-glue.c.356)
HTTP["useragent"] ( Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1) ) compare to MSIE 
2006-04-02 13:40:07: (src/configfile-glue.c.419) 1 result: true

See also: advanced configuration in 1.4.x, lighttpd unleashed part one, lighttpd unleashed part two

lighttpd unleashed - part two 2

Posted by jan Wed, 24 Aug 2005 09:24:00 GMT

The big thing of lighttpd 1.4.0 were the nested conditionals, but how can they be used ? And what are includes ?

A example for nested confitionals went already into the announcement:

$HTTP["host"] == "www.example.org" {
  $HTTP["url"] =~ "^/dav($|/)" {
    webdav.activate = "enable" 
  }
  $HTTP["remoteip"] != "10.0.0.0/16" {
    auth.require = ( "" => ( "method" => "basic",
                             "realm" => "webdav",
                             "require" => "valid-user" ) )
  }
}

But what are includes for ? For a start we want to go the mass-hosting way and want to create a generic pattern for virtual hosts without using mod_simple_vhost or similar modules.

We have a simple webserver structure:

  • all servers are under /var/www/servers/
  • the part is the hostname of the server
  • and logs and public files are at logs/ and pages/

resulting in /var/www/servers/www.example.org/pages/.

In lighttpd 1.3.x you had to copy the conditionals for all host including all the options. There was no way to do some interpretation of the config file.

In lighttpd 1.4.0 this has changed and we can use expressions and includes:

server.document-root = "/tmp" 
server.port = 1025

server.modules = ( "mod_access" )

access.deny = ( "~", ".inc" )

$HTTP["host"] == "www.example.org" {
  var.hostname = "www.example.org" 
  include "baseconfig.conf" 
}

$HTTP["host"] == "www2.example.org" {
  var.hostname = "www2.example.org" 
  include "baseconfig.conf" 
}

and a baseconfig.conf

server.document-root = "/var/www/servers/" + hostname + "/pages/" 
access.logfile = "/var/www/servers/" + hostname + "/logs/accesslog" 

With var.hostname you can set a user-variable in the configuration which can be used everywhere in the config to pass data around. We use it here to substiture the parts of the baseconfig for each host and set the document-root and the location of the accesslog for each host.

But how does the config look like that is used by lighttpd ? The option -p will tell us:

$ /lighttpd -p -f ./lighttpd-includes.conf
config {
    server.document-root = "/tmp" 
    server.port          = 1025
    server.modules       = ("mod_indexfile", "mod_access", "mod_dirlisting", "mod_staticfile")
    access.deny          = ("~", ".inc")

    $HTTP["host"] == "www.example.org" {
        # block 1
        var.hostname         = "www.example.org" 
        server.document-root = "/var/www/servers/www.example.org/pages/" 
        access.logfile       = "/var/www/servers/www.example.org/logs/accesslog" 

    } # end of $HTTP["host"] == "www.example.org" 

    $HTTP["host"] == "www2.example.org" {
        # block 2
        var.hostname         = "www2.example.org" 
        server.document-root = "/var/www/servers/www2.example.org/pages/" 
        access.logfile       = "/var/www/servers/www2.example.org/logs/accesslog" 

    } # end of $HTTP["host"] == "www2.example.org" 
}

Nice, isn’t it ? :)