Project

General

Profile

[Solved] mod_vhost in lighttpd2

Added by Torxed about 9 years ago

For those googling having a hard time figuring out lighttpd2 and it's vhost functionality.

Change /etc/lighttpd2.conf to comment out:
#docroot "/srv/http";

Also add "mod_vhost";@ in the setup module_load block.

Then add (under any other include):
include "/etc/lighttpd2/vhost.conf";"

And finally create a /etc/lighttpd2/vhost.conf file matching:

example = {
docroot "/srv/http/testFolder";
};

defaultzone = {
docroot "/srv/http";
};

vhost.map ["ex.ample.net" => example, default => defaultzone];

And you're all done.
What confused me was that docroot isn't overwritten by the mod_vhost. I would assume that the addon which should be later in the "activation line" would write over any global/default config, and maybe it will. But for now this is how it is so make sure to comment it out.


Replies (1)

RE: [Solved] mod_vhost in lighttpd2 - Added by stbuehler about 9 years ago

No.

mod_vhost doesn't set docroot - it executes config blocks depending on the hostname.

The last docroot action that was run determines the current value of the physical path; and other actions will use this value at the moment they are called.

But yes, if you want to use vhosts it is a good idea to remove the default docroot and replace it by vhost.map.

A vhost.conf containing all vhosts is not a good way to maintain your lighttpd2 config; after some time it will be just some big file.

Try something like this instead in the main config (or in vhost.conf - but this is small enough for the main config):

var.vhosts = [];
include "/etc/lighttpd2/vhosts/*.conf";
vhost.map var.vhosts;

And put each vhost config into its on file, like our /etc/lighttpd2/vhosts/download.lighttpd.net.conf:

var.vhosts = var.vhosts + [
        "download.lighttpd.net" => {
                docroot "/var/www/servers/download.lighttpd.net";
                alias ( "/robots.txt" => "/var/www/common/robots.txt");
                index ("index.html");
                dirlist ( "encode-readme" => false );
        }
];

PS: For the main vhost config we actually use the nested map + map_regex:

        var.vhosts = [];
        var.regex_vhosts = [];
        include "/etc/lighttpd2/vhosts/*.conf";

        var.vhosts = var.vhosts + [ default => { vhost.map_regex var.regex_vhosts; } ];

        vhost.map var.vhosts;
    (1-1/1)