<?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: lighttpd unleashed - part two</title>
    <link>http://blog.lighttpd.net/articles/2005/08/24/lighttpd-unleashed-part-two</link>
    <language>en-us</language>
    <ttl>40</ttl>
    <description></description>
    <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>
    <item>
      <title>"lighttpd unleashed - part two" by free real music ringtone for nextel</title>
      <description>Such good article without comments? Bad :(</description>
      <pubDate>Sun, 18 Jun 2006 15:35:20 +0000</pubDate>
      <guid isPermaLink="false">urn:uuid:246dd847-3efd-471f-9d76-78f3c8a196ff</guid>
      <link>http://blog.lighttpd.net/articles/2005/08/24/lighttpd-unleashed-part-two#comment-1574</link>
    </item>
    <item>
      <title>"lighttpd unleashed - part two" by Tom</title>
      <description>It should be noted that constructs that include variables, such as the:

server.document-root = "/var/www/servers/" + hostname + "/pages/" 

line can only occur inside if statements like $HTTP["HOST"] =~ "whatever" {  ... } 

This puzzled me for a while and should be better explained in the docs.</description>
      <pubDate>Fri, 30 Dec 2005 21:01:50 +0000</pubDate>
      <guid isPermaLink="false">urn:uuid:88c222b6-2f3b-4e42-b70e-79d3065e0f08</guid>
      <link>http://blog.lighttpd.net/articles/2005/08/24/lighttpd-unleashed-part-two#comment-85</link>
    </item>
  </channel>
</rss>
