<?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 configfile</title>
    <link>http://blog.lighttpd.net/articles/tag/configfile</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>simplify your configfiles with includes</title>
      <description>&lt;p&gt;Or should it be named &amp;#8216;virtual hosting made easy ?&amp;#8217; Anyway. If your vhosting setup looks a bit more complext like having different options (static only, php support, pre-installed rails apps, ...) but a similar setup for each you can&amp;#8217;t use the vhosting modules and have to write everything by hand. But there is rescue thanks to includes and variables.&lt;/p&gt;
&lt;p&gt;The idea is to modularize the configfile and only include the parts of the config for a vhost that it needs.&lt;/p&gt;


	&lt;p&gt;But first we define our setup:&lt;/p&gt;


	&lt;ol&gt;
	&lt;li&gt;All vhosts are under &lt;em&gt;_ /var/www/servers/&lt;domain&gt;/pages/ _&lt;/em&gt;&lt;/li&gt;
		&lt;li&gt;you have some vhost that have protected folders&lt;/li&gt;
		&lt;li&gt;some may have &lt;span class="caps"&gt;PHP&lt;/span&gt; support, some may use pre-installed rails apps&lt;/li&gt;
	&lt;/ol&gt;


The classic way is:
&lt;pre&gt;
$HTTP["host"] == "www.example.org" {
  server.document-root = "/var/www/servers/www.example.org/pages/" 
  auth.backend = "htpasswd" 
  auth.backend.htpasswd.userfile = "/var/www/servers/www.example.org/htpasswd" 
  auth.require = ... 
}
&lt;/pre&gt;

	&lt;p&gt;We specify the path in the full lenth both times. Let&amp;#8217;s tackle this one first:&lt;/p&gt;


&lt;pre&gt;
$HTTP["host"] == "www.example.org" {
  var.basedir = "/var/www/servers/www.example.org/" 
  server.document-root = basedir + "pages/" 
  auth.backend = "htpasswd" 
  auth.backend.htpasswd.userfile = basedir + "/htpasswd" 
  auth.require = ... 
}
&lt;/pre&gt;

	&lt;p&gt;But this is just one host, let&amp;#8217;s add another one, just serving static files:&lt;/p&gt;


&lt;pre&gt;
$HTTP["host"] == "www.example.com" {
  var.basedir = "/var/www/servers/www.example.com/" 
  server.document-root = basedir + "pages/" 
}
&lt;/pre&gt;

	&lt;p&gt;Both have the same directory root &lt;em&gt;_ /var/www/servers/ _&lt;/em&gt; let&amp;#8217;s move it out.&lt;/p&gt;


&lt;pre&gt;
var.basedir = "/var/www/servers/" 
$HTTP["host"] == "www.example.org" {
  var.servername = "www.example.org" 

  server.document-root = basedir + servername + "/pages/" 
  auth.backend = "htpasswd" 
  auth.backend.htpasswd.userfile = basedir + servername + "/htpasswd" 
  auth.require = ... 
}
$HTTP["host"] == "www.example.com" {
  var.servername = "www.example.com" 

  server.document-root = basedir + servername + "/pages/" 
}
&lt;/pre&gt;

	&lt;p&gt;The server.document-root setting is now exactly the same for both servers, let&amp;#8217;s move it out again, this time into a include file called &lt;em&gt;_ incl-docroot.conf _&lt;/em&gt;:&lt;/p&gt;


&lt;pre&gt;
## set the docroot based on basedir and servername 
## both have to be defined before
  server.document-root = basedir + servername + "/pages/" 
&lt;/pre&gt;

	&lt;p&gt;and here is our new configfile:&lt;/p&gt;


&lt;pre&gt;
var.basedir = "/var/www/servers/" 
$HTTP["host"] == "www.example.org" {
  var.servername = "www.example.org" 

  include "incl-docroot.conf" 

  auth.backend = "htpasswd" 
  auth.backend.htpasswd.userfile = basedir + servername + "/htpasswd" 
  auth.require = ( "/download" =&amp;gt; ... )
}
$HTTP["host"] == "www.example.com" {
  var.servername = "www.example.com" 

  include "incl-docroot.conf" 
}
&lt;/pre&gt;

	&lt;p&gt;Last step is moving the auth part into a include-file too called &lt;em&gt;_ incl-auth-htpasswd.conf _&lt;/em&gt;:&lt;/p&gt;


&lt;pre&gt;
## set authentificate for a directory
auth.backend = "htpasswd" 
auth.backend.htpasswd.userfile = basedir + servername + "/htpasswd" 
auth.require = ( authdir =&amp;gt; ... )
&lt;/pre&gt;

	&lt;p&gt;and our configfile:&lt;/p&gt;


&lt;pre&gt;
var.basedir = "/var/www/servers/" 
$HTTP["host"] == "www.example.org" {
  var.servername = "www.example.org" 
  var.authdir = "/download/" 

  include "incl-docroot.conf" 
  include "incl-auth-htpasswd.conf" 
}
$HTTP["host"] == "www.example.com" {
  var.servername = "www.example.com" 

  include "incl-docroot.conf" 
}
&lt;/pre&gt;

	&lt;p&gt;Ok, last step is FastCGI for a host. We create a include-file from the start called &lt;em&gt;_ incl-fastcgi-php.conf _&lt;/em&gt;:&lt;/p&gt;


&lt;pre&gt;
fastcgi.server = ( ".php" =&amp;gt; ((
  "bin-path" =&amp;gt; "/usr/bin/php-cgi",
  "socket" =&amp;gt; basedir + servername + "/tmp/php-" + PID + ".socket" 
)))
&lt;/pre&gt;

	&lt;p&gt;If a host wants &lt;span class="caps"&gt;PHP&lt;/span&gt; support we just include this file:&lt;/p&gt;


&lt;pre&gt;
var.basedir = "/var/www/servers/" 
$HTTP["host"] == "www.example.org" {
  var.servername = "www.example.org" 
  var.authdir = "/download/" 

  include "incl-docroot.conf" 
  include "incl-auth-htpasswd.conf" 
}
$HTTP["host"] == "www.example.com" {
  var.servername = "www.example.com" 

  include "incl-docroot.conf" 
  include "incl-fastcgi-php.conf" 
}
&lt;/pre&gt;

	&lt;p&gt;Which leads to the last issue: than one name for a vhost. Let&amp;#8217;s say &lt;em&gt;_ www.example.org _&lt;/em&gt; and &lt;em&gt;_ example.org _&lt;/em&gt;  are the same vhost with different names.&lt;/p&gt;


&lt;pre&gt;
var.basedir = "/var/www/servers/" 
$HTTP["host"] =~ "^(www\.)?example\.org$" {
  var.servername = "www.example.org" 
  var.authdir = "/download/" 

  include "incl-docroot.conf" 
  include "incl-auth-htpasswd.conf" 
}
$HTTP["host"] == "www.example.com" {
  var.servername = "www.example.com" 

  include "incl-docroot.conf" 
  include "incl-fastcgi-php.conf" 
}
&lt;/pre&gt;

	&lt;p&gt;Now I leave it up to you to write a web-frontend to generate these modular configfiles for your setup.&lt;/p&gt;


	&lt;p&gt;Include and variables work since 1.4.0, the &lt;span class="caps"&gt;PID&lt;/span&gt; variable is available since 1.4.6 &lt;span class="caps"&gt;IIRC&lt;/span&gt;.&lt;/p&gt;</description>
      <pubDate>Fri, 25 Nov 2005 13:45:00 +0000</pubDate>
      <guid isPermaLink="false">urn:uuid:d225d844-e1ce-4e83-88b3-7dd4c235f206</guid>
      <author>jan</author>
      <link>http://blog.lighttpd.net/articles/2005/11/25/simplify-your-configfiles-with-includes</link>
      <category>configfile</category>
      <category>includes</category>
      <trackback:ping>http://blog.lighttpd.net/articles/trackback/46</trackback:ping>
    </item>
  </channel>
</rss>
