<?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: simplify your configfiles with includes</title>
    <link>http://blog.lighttpd.net/articles/2005/11/25/simplify-your-configfiles-with-includes</link>
    <language>en-us</language>
    <ttl>40</ttl>
    <description></description>
    <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>
    <item>
      <title>"simplify your configfiles with includes" by eloy@debian.org</title>
      <description>If would be nice if lighttpd allows empty initialization of "configuration arrays". I mean something like:

server.modules += ( "mod_alias" )
alias.url = ()

then somewhere else

alias.url += ( "/doc/" = "/var/doc" )

or second solution += operator could initialize "configuration arrays"</description>
      <pubDate>Wed, 11 Jan 2006 20:36:32 +0000</pubDate>
      <guid isPermaLink="false">urn:uuid:e4c207ce-dc98-4614-ad36-8d4cb9833851</guid>
      <link>http://blog.lighttpd.net/articles/2005/11/25/simplify-your-configfiles-with-includes#comment-93</link>
    </item>
    <item>
      <title>"simplify your configfiles with includes" by Simon Lange</title>
      <description>i did not talk about reload. reload works but manual reloading is no wished. i did talk about mysql_vhost and the inconsequence in adding mysql_vhost but not adding features so u have everything related to virtualhosting in database. it could be pretty simple just by adding a text field to the table and use this the same way as a HTTP["host"] directive. as long we have to put virtualhosting into lighty's conf although we use mysql_vhost, the advantage of mysql_vhost is wasted.

Simon</description>
      <pubDate>Sat, 31 Dec 2005 13:12:05 +0000</pubDate>
      <guid isPermaLink="false">urn:uuid:c8ac2b57-53e0-496f-8ade-b0d6d567a79d</guid>
      <link>http://blog.lighttpd.net/articles/2005/11/25/simplify-your-configfiles-with-includes#comment-86</link>
    </item>
    <item>
      <title>"simplify your configfiles with includes" by yo </title>
      <description>like suggested a dyn conf file generator
&lt;a href="http://www.bigbold.com/snippets/posts/show/1017" rel="nofollow"&gt;http://www.bigbold.com/snippets/posts/show/1017&lt;/a&gt;</description>
      <pubDate>Sun, 25 Dec 2005 23:46:47 +0000</pubDate>
      <guid isPermaLink="false">urn:uuid:d2272b49-9013-4829-94a4-cb15e6956f88</guid>
      <link>http://blog.lighttpd.net/articles/2005/11/25/simplify-your-configfiles-with-includes#comment-83</link>
    </item>
    <item>
      <title>"simplify your configfiles with includes" by Patrick</title>
      <description>Cool :)</description>
      <pubDate>Sun, 25 Dec 2005 06:08:46 +0000</pubDate>
      <guid isPermaLink="false">urn:uuid:e7f89e66-4d0b-44f4-85d3-6ecff37baafb</guid>
      <link>http://blog.lighttpd.net/articles/2005/11/25/simplify-your-configfiles-with-includes#comment-82</link>
    </item>
    <item>
      <title>"simplify your configfiles with includes" by Yo</title>
      <description>ok sorry i found one of your older post which explains the reload thing. ;)

&lt;a href="http://blog.lighttpd.net/articles/2005/09/02/graceful-restart" rel="nofollow"&gt;http://blog.lighttpd.net/articles/2005/09/02/graceful-restart&lt;/a&gt;</description>
      <pubDate>Tue, 20 Dec 2005 23:03:04 +0000</pubDate>
      <guid isPermaLink="false">urn:uuid:dbaaee6d-9356-4852-a0f2-eedacb18136e</guid>
      <link>http://blog.lighttpd.net/articles/2005/11/25/simplify-your-configfiles-with-includes#comment-81</link>
    </item>
    <item>
      <title>"simplify your configfiles with includes" by Yo</title>
      <description>Simons right. Everytime the conifg changes lighty has to be restarted. This would be a thing i would love to see fixed in 1.5 ;-)</description>
      <pubDate>Mon, 19 Dec 2005 16:28:42 +0000</pubDate>
      <guid isPermaLink="false">urn:uuid:512666a4-4571-4141-9540-3615c405083a</guid>
      <link>http://blog.lighttpd.net/articles/2005/11/25/simplify-your-configfiles-with-includes#comment-80</link>
    </item>
    <item>
      <title>"simplify your configfiles with includes" by Simon Lange sl@polynaturedesign.com</title>
      <description>nice feature but better would be a possibility to add those includes into mysql_vhost too or even better: what about a text field more which is a list of settings which were usually in brackets in the lighty conf?!

that would kick really sum butts ;) also i dont want to reload/restart the webserver everytime a new customers comes in, thats why we usin mysql_vhost.

regards Simon</description>
      <pubDate>Fri, 16 Dec 2005 17:43:15 +0000</pubDate>
      <guid isPermaLink="false">urn:uuid:753996ae-1fa0-4f58-bbad-dc2192139ed5</guid>
      <link>http://blog.lighttpd.net/articles/2005/11/25/simplify-your-configfiles-with-includes#comment-78</link>
    </item>
    <item>
      <title>"simplify your configfiles with includes" by Kev</title>
      <description>To 'Infest':
I compiled Lighttpd with Cygwin on Windows, and made a Windows setup package to install it on Windows 2000 or XP, without the need for Cygwin. In other words, download the setup and run it, and Lighttpd will be up and running on Windows. I included a README file of how to do things in regards to my packaged version, but for all other inquiries, see lighttpd.net.</description>
      <pubDate>Thu, 01 Dec 2005 16:03:26 +0000</pubDate>
      <guid isPermaLink="false">urn:uuid:a0c70097-a054-4069-9e75-cb76d9ed63d7</guid>
      <link>http://blog.lighttpd.net/articles/2005/11/25/simplify-your-configfiles-with-includes#comment-63</link>
    </item>
    <item>
      <title>"simplify your configfiles with includes" by Infest</title>
      <description>Sorry.. but ineed to know. IS THAT LIGHTHTTPD works on WINDOWS. or XP or 2000 ....


idont find anysupport. Let me know it.</description>
      <pubDate>Tue, 29 Nov 2005 17:28:51 +0000</pubDate>
      <guid isPermaLink="false">urn:uuid:99be3c94-8f1a-4925-ae6c-003db6f135c4</guid>
      <link>http://blog.lighttpd.net/articles/2005/11/25/simplify-your-configfiles-with-includes#comment-61</link>
    </item>
    <item>
      <title>"simplify your configfiles with includes" by Kev</title>
      <description>I've put together a Windows setup for version 1.4.7, available here: &lt;a href="http://www.kevinworthington.com:8181/?p=85" rel="nofollow"&gt;http://www.kevinworthington.com:8181/?p=85&lt;/a&gt;</description>
      <pubDate>Sat, 26 Nov 2005 19:37:54 +0000</pubDate>
      <guid isPermaLink="false">urn:uuid:c727893e-b5f5-472e-9da6-a5337b33113c</guid>
      <link>http://blog.lighttpd.net/articles/2005/11/25/simplify-your-configfiles-with-includes#comment-50</link>
    </item>
    <item>
      <title>"simplify your configfiles with includes" by Win</title>
      <description>Hi lighty, just my 2 cents totally off topic.

I've just spent cca 20 minutes trying to figure how to run httpd on windows. No success, so I'm feeling totally dumb.

I've got WAMP on development machine, and linux on the server [which I do not administer].

Have you ever consider to make it easier for guys like me to offer win port of lighttpd?

If windows developers (me :) could try lighttpd in their enviroment, they may help to increase  number of lighhtpd instalations on linux servers :) 

[Sorry 4 my eng]</description>
      <pubDate>Fri, 25 Nov 2005 15:46:15 +0000</pubDate>
      <guid isPermaLink="false">urn:uuid:8d5ad4d5-a488-4704-b6fc-1b696c0c09e0</guid>
      <link>http://blog.lighttpd.net/articles/2005/11/25/simplify-your-configfiles-with-includes#comment-47</link>
    </item>
  </channel>
</rss>
