Posted by funkyhat on February 18, 2010 at 2:03am
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 ⢁)
| Attachment | Size |
|---|---|
| drupal6.txt | 1.49 KB |

Comments
I've updated the script to
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
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 thefindcommand 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.
The Boise Drupal Guy!
No worries :) include_shell
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
[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:
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-hostdirectory. 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 thesimple-vhost.default-hostdirectory). 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:
…Where the lines in between the curly brackets could be config stuff,
includelines 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.
The Boise Drupal Guy!
I wasn't aware of
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
From http://redmine.lighttpd.net/projects/lighttpd/wiki/Docs:Configuration
# read configuration from output of a commandinclude_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
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.
The Boise Drupal Guy!
Lighttpd Clean url for a drupal site
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...