multi site with lighttpd

Events happening in the community are now at Drupal community events on www.drupal.org.
funkyhat's picture

I wasn't happy with the vhost modules in lighttpd, I host a few drupal sites on a multisite setup, as well as a few non-drupal sites, so a single way of defining vhosts was a bit too restrictive. I came up with a script which is loaded by include_script, based on this howto. I'm using the mod_magnet script from here.

My script is attached, and I've talked about this in a little more detail at http://funkyhat.org/2010/02/18/drupal-multisite-in-lighttpd/

Hopefully others will find this useful ⢁)

AttachmentSize
drupal6.txt1.49 KB

Comments

I've updated the script to

funkyhat's picture

I've updated the script, with help from darix on irc.freenode.net/#lighttpd, to use a deny rule rather than aliases. Apparently I didn't test the aliases well enough and they weren't actually working.

Just now got around to

Garrett Albright's picture

Just now got around to checking this out… sorry for the slow reply.

I don't really like the idea of using include_shell… doesn't that start a whole new shell process for every single hit to the server?! And then the find command starts another one… Two new process for every single hit can't be performant.

Shell scripting isn't really my forte - could you elaborate on what this script is doing that couldn't be accomplished by Drupal's standard virtual host modules? I personally use mod_simple_vhost for everything and am in love with its elegant simplicity.

No worries :) include_shell

funkyhat's picture

No worries :)

include_shell just calls the shell script to generate the config, so it'll only be called once when lighttpd is started up.

I found lighttpd's vhost modules too restrictive - they seem to be all or nothing affairs, unless you want your config to get messy. The script I wrote adds specific hostnames based on the contents of drupal's sites dir, which leaves me free to configure other hostnames how I want.

The script also sets up restricted access to the sites dir per host, something which I think would be much more complex to do otherwise. It blocks access to all but sites/ and sites/all. I know that's not a particularly pressing issue - who is to know which sites to look for? Still I'd rather not have nonsensical urls like http://some-site.ext/sites/another-site.ext/files/afile.png reslove to an actual file.

It also allows me to add custom configs per host, though I'm using that for one drupal site which doesn't have a standard files path to override my access restrictions ;).

I could just use mod_simple_vhost and create symlinks to /my/drupal/dir for each drupal site, but as far as I can tell I'd lose the ability to add custom configs per site and my access restrictions. I'd also be tied in to using mod_simple_vhost for any non-drupal sites.

include_shell just calls the

Garrett Albright's picture

include_shell just calls the shell script to generate the config, so it'll only be called once when lighttpd is started up.

[Citation needed.] Are you sure about that? I haven't found anything supporting that in Lighty's docs - but then again, I haven't found anything supporting that it'll run once for each hit either.

I think you may have some misunderstandings of how mod_simple_vhost works. We are using it to host both a large multi-site Drupal 6 installation as well as a smattering of non-Drupal or Drupal 5-powered sites.

Consider that your web root looks like this:

html-site.xyz
wordpress-site.xyz
drupal-multisite.xyz

What happens if you configure mod_simple_vhost like this:

simple-vhost.server-root = "/path/to/web/root/"
simple-vhost.default-host = "drupal-multisite.xyz"
simple-vhost.document-root = "/"

When Lighty gets a request for any given domain name, it will first check to see if a directory matching that domain name exists in the web root. If so, it will host from that directory; if not, it will host from the simple-vhost.default-host directory. If you want to add another Drupal multisite, just add the directory to Drupal's sites folder as normal and away you go. If you want to add another non-Drupal site, just add a new directory to the web root which matches the new site's domain name and away you go (though Lighty seems to cache which directory it uses for which domain name, so you may need to restart it if it looks like it's still trying to host from the simple-vhost.default-host directory). That is so wonderfully easy! And you don't need a script to add host names based on Drupal's sites directory - it happens automatically.

It doesn't solve your cross-site file problem, no, but that could be taken care of at the Lua layer if you really think it's a problem (it doesn't bother me, personally, because if I never link to a file at a path like that, it effectively doesn't exist). And, no, that in itself won't allow you to use custom config files per host, though it's still possible (if a little painful) to do just in the configuration file, without resorting to anything external:

$HTTP["host"] == "html-site.xyz" {
  # stuff
}
else $HTTP["host"] == "wordpress-site.xyz" {
  # stuff
}
else $HTTP["host"] != "" {
  # default stuff - note that Lighty's config syntax doesn't support "else" by itself
}

…Where the lines in between the curly brackets could be config stuff, include lines if you really must have each site's config stuff in separate files, or both. (Lighty 1.5 will give us a $PHYSICAL["path"] which will probably work a little better for this sort of thing.)

This is all a generalization of how I've been operating my company's Lighty-powered web server in the real world for almost a year now.

I wasn't aware of

funkyhat's picture

I wasn't aware of simple-vhost.default-host, perhaps it didn't click when I read that part of the documentation. That does indeed make it a lot more compatible with drupal multisite usage.

However, I'm still going to be restricted by that if I use any other software which has multi site capabilities. So I think I'll stick with my script, even though it might not be that useful for general consumption :).

From

funkyhat's picture

From http://redmine.lighttpd.net/projects/lighttpd/wiki/Docs:Configuration

# read configuration from output of a command
  include_shell "/usr/local/bin/confmimetype /etc/mime.types"

My (limited) experience with include_shell also confirms that the script is only run on launch of lighttpd. The documentation could be clearer on that point though :)

I don't know if that's

Garrett Albright's picture

I don't know if that's conclusive, but in retrospect, since the Lighty process itself only reads its own .conf files once, I suppose it makes sense that it would only read those generated from shell scripts once as well.

Lighttpd Clean url for a drupal site

karthick62's picture

Hi,

I have started using drupal on lighttpd for the few days.. My directory set up goes like this .

1./document-root/site
2./document-root/site/subsite1
3./document-root/site/subsite2
I am able to get the clean urls for the above sites using lua scripts. I have no problem on accessing the pages using both apache and lighttpd

But I got another site,like

4./document-root/site/subsite3/subsite3.1

When I click the pages on the subsite3 and subsite3.1 I am getting page not found errors when I use lighttpd. but it works fine with apache2. I need help on this.

Thanks in advance...

Lighttpd

Group organizers

Group notifications

This group offers an RSS feed. Or subscribe to these personalized, sitewide feeds: