<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/css" href="/stylesheets/rss.css"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/">
  <channel>
    <title>lighty's life: Tag conditionals</title>
    <link>http://blog.lighttpd.net/articles/tag/conditionals</link>
    <language>en-us</language>
    <ttl>40</ttl>
    <description></description>
    <item>
      <title>log-condition-handling, The hidden feature for debuging</title>
      <description>&lt;p&gt;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.&lt;/p&gt;
&lt;p&gt;It was originally implemented to debug the new condition caching system internally for developers only.&lt;/p&gt;

&lt;p&gt;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.&lt;/p&gt;

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

&lt;p&gt;./sbin/ligittpd -pf test.conf&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;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"
}
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;./sbin/lighttpd -Df test.conf&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;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
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;See also: &lt;a href="http://blog.lighttpd.net/articles/2005/05/07/advanced-configuration-in-up-upcoming-1-4-x"&gt;advanced configuration in 1.4.x&lt;/a&gt;, 
&lt;a href="http://blog.lighttpd.net/articles/2005/08/24/lighttpd-unleashed-part-one"&gt;lighttpd unleashed part one&lt;/a&gt;, 
&lt;a href="http://blog.lighttpd.net/articles/2005/08/24/lighttpd-unleashed-part-two"&gt;lighttpd unleashed part two&lt;/a&gt;&lt;/p&gt;</description>
      <pubDate>Sun, 02 Apr 2006 05:46:00 +0000</pubDate>
      <guid isPermaLink="false">urn:uuid:cd2202e1-64cf-44b0-af65-b52371220518</guid>
      <author>moo</author>
      <link>http://blog.lighttpd.net/articles/2006/04/02/log-condition-handling-the-hidden-feature-for-debuging</link>
      <category>lighttpd</category>
      <category>debuging</category>
      <category>configfile</category>
      <category>configuration</category>
      <category>conditionals</category>
      <trackback:ping>http://blog.lighttpd.net/articles/trackback/159</trackback:ping>
    </item>
    <item>
      <title>lighttpd unleashed - part two</title>
      <description>&lt;p&gt;The big thing of lighttpd 1.4.0 were the nested conditionals, but how can they be used ? And what are includes ?&lt;/p&gt;
&lt;p&gt;A example for nested confitionals went already into the announcement:&lt;/p&gt;


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

	&lt;p&gt;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.&lt;/p&gt;


	&lt;p&gt;We have a simple webserver structure:&lt;/p&gt;


	&lt;ul&gt;
	&lt;li&gt;all servers are under /var/www/servers/&lt;/li&gt;
		&lt;li&gt;the part is the hostname of the server&lt;/li&gt;
		&lt;li&gt;and logs and public files are at logs/ and pages/&lt;/li&gt;
	&lt;/ul&gt;


	&lt;p&gt;resulting in &lt;code&gt;/var/www/servers/www.example.org/pages/&lt;/code&gt;.&lt;/p&gt;


	&lt;p&gt;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.&lt;/p&gt;


	&lt;p&gt;In lighttpd 1.4.0 this has changed and we can use expressions and includes:&lt;/p&gt;


&lt;pre&gt;
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" 
}
&lt;/pre&gt;

	&lt;p&gt;and a baseconfig.conf&lt;/p&gt;


&lt;pre&gt;
server.document-root = "/var/www/servers/" + hostname + "/pages/" 
access.logfile = "/var/www/servers/" + hostname + "/logs/accesslog" 
&lt;/pre&gt;

	&lt;p&gt;With &lt;code&gt;var.hostname&lt;/code&gt; 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.&lt;/p&gt;


	&lt;p&gt;But how does the config look like that is used by lighttpd ? The option &lt;code&gt;-p&lt;/code&gt; will tell us:&lt;/p&gt;


&lt;pre&gt;
$ /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" 
}
&lt;/pre&gt;

	&lt;p&gt;Nice, isn&amp;#8217;t it ? :)&lt;/p&gt;</description>
      <pubDate>Wed, 24 Aug 2005 09:24:00 +0000</pubDate>
      <guid isPermaLink="false">urn:uuid:3c9ab0d9f35165920c5de806b90f0ab1</guid>
      <author>jan</author>
      <link>http://blog.lighttpd.net/articles/2005/08/24/lighttpd-unleashed-part-two</link>
      <category>lighttpd</category>
      <category>lighttpd</category>
      <category>nested</category>
      <category>conditionals</category>
      <category>configuration</category>
      <trackback:ping>http://blog.lighttpd.net/articles/trackback/16</trackback:ping>
    </item>
  </channel>
</rss>
