lighttpd simple-vhost question

Hi everyone, please excuse the simple question but i've been driving myself nuts trying to find some form of example of using simple-vhost for multiple domains without having to set up each one myself.

I've used the following

> simple-vhost.server-root = "/var/www/"

simple-vhost.default-host = "localhost"

simple-vhost.document-root = "/www/"

Which works fine for http://domain1.com and http://domain2.com but trying to go to http://www.domain1.com or http://www.domain2.com does not work :( I'm guessing I'm missing something really simple but can't seem to find any examples at all.

Any help would be great, thanks in advance

5 Replies

with lighttpd simply vhosts, you create a subdirectory for each virtual host you want.

eg

mkdir /var/www/domain1.com
mkdir /var/www/domain2.com

Now "www.domain1.com" is different to "domain1.com".

So what I do is symlink them

cd /var/www
ln -s domain1.com www.domain1.com

Now requests for "domain1.com" and "www.domain1.com" are both served from the same tree.

I don't use lighttpd but I did try to set it up last night.

From what I've read the vhost looks in the directory name based on those three settings.

So for domain1.com would be /var/www/domain1.com/www/ and www.domain1.com would be /var/www/www.domain1.com/www

Is it as easy as putting a sym link for www.domain1.com into that directory?

Two ways to do it:

1) The symlink method. This works just fine.

2) The redirect method. I've become cantankerous and determined that http://www.domain.com/ is redundant, so I've now standardized upon http://domain.com/. This also means /var/www is much neater because there's not a lot of symlinks all around.

Anyway, here's the config I'm using for that:

$HTTP["host"] !~ "^(www\..*)$" {
        ## The document root of a virtual host isdocument-root =
        ##   simple-vhost.server-root + $HTTP["host"] + simple-vhost.document-root
        simple-vhost.server-root         = "/var/www"
        simple-vhost.document-root       = "/html/"

        ## the default host if no host is sent
        simple-vhost.default-host        = "default-fall-through.hoopycat.com"
}

# www.*
$HTTP["host"] =~ "^www\.(.*)" { url.redirect = ( "^/(.*)" => "http://%1/$1" ) }

Doing it the other way – redirecting from http://domain.com/ to http://www.domain.com/ -- is left as an exercise for the reader.

hoopycat - thank you for your post, gave me a good idea for what i'm looking for, although i will prefer not to use the URL redirect on the www. but you have give me a good example and i should be able to take it from here :)

I'm slightly confused and think im trying to create too complex a setup for my vhosts.

I thought it would be possible to setup something using simple-vhost that could capture the domain and any possible sub-domains for any pointed to my linode.

I've been trying to find other examples after the one hoopycat posted but failed.

Can you use regex with simple-vhost?

Reply

Please enter an answer
Tips:

You can mention users to notify them: @username

You can use Markdown to format your question. For more examples see the Markdown Cheatsheet.

> I’m a blockquote.

I’m a blockquote.

[I'm a link] (https://www.google.com)

I'm a link

**I am bold** I am bold

*I am italicized* I am italicized

Community Code of Conduct