Project

General

Profile

Document-root not needed with virtual hosts

Added by lafayette about 15 years ago

Hi all,

I'm pretty new to lighttpd but I managed to get a basic setup running without too much effort.
Anyway, still something bothers me and I've no idea on a workaround to solve it.

I have two virtual hosts on the same IP (not using simple-vhost); both sites have a directory inside /var/www:

/var/www/vhost1 and /var/www/vhost2

I was also required to set server.document-root and I chose /var/www. Now, if someone enters the IP address of the server and a directory, is served by lighttpd with the site (e.g. http://11.22.33.44/vhost1)

Any way to avoid this behaviour, and serve pages only if host is specified?


Replies (8)

RE: Document-root not needed with virtual hosts - Added by khinester about 15 years ago

hi can you post your lighttpd.conf file as i have a similar issue.
thanks

RE: Document-root not needed with virtual hosts - Added by lafayette about 15 years ago

For what refers to virtual hosts section:

$HTTP["host"] == "www.nerdpride.org" {
    server.document-root = "/var/www/www.nerdpride.org" 

}

$HTTP["host"] == "vps20.vz20.ramhost.us" {
    server.document-root = "/var/www/vps20.vz20.ramhost.us" 

}

## End Virtual hosts

## a static document-root, for virtual-hosting take look at the
## server.virtual-* options
server.document-root       = "/var/www/" 

RE: Document-root not needed with virtual hosts - Added by icy about 15 years ago

Try this:

$HTTP["host"] !~ "^(www\.nerdpride\.org|vps20\.vz20\.ramhost\.us)(:\d+)?$" {
   url.access-deny = ("")
}

It checks if the host is neither of the ones you defined and if true denies access to the server (error page 403).

RE: Document-root not needed with virtual hosts - Added by lafayette about 15 years ago

that's good. Anyway, that regexp would scale with respect to the number of virtual hosts.

Maybe blocking access when host is IP number would work?

RE: Document-root not needed with virtual hosts - Added by skelkingur about 15 years ago

Just use mod_simple_vhost:

http://redmine.lighttpd.net/projects/lighttpd/wiki/Docs:ModSimpleVhost

You can specify a default-host that is served if no valid vhost is requested (which is the case if you call the server using it's IP).

Cheers,
Fabian

RE: Document-root not needed with virtual hosts - Added by lafayette about 15 years ago

In the ending section it says:

You do not need to use two entries for example.com and www.example.com. The following syntax will act as a catch all for both example.com and any subdomains under it:

$HTTP["host"] =~ "(^|\.)example\.com$" {
    ...
}

(Doesn't work for you? If you're not running on the default port, $HTTP["host"] will have the port number appended and the above reg-ex won't match it, since the trailing "$" means "the-string-ends-this-way".)

So for example, if I put smtp.mydomain.net I will get presented with mydomain.net/ directory contents, which is something that I don't want (I'd like www.mydomain.net only access)

RE: Document-root not needed with virtual hosts - Added by skelkingur about 15 years ago

"you dont need to"

$HTTP["host"] =~ "^(www\.mydomain\.net|mydomain\.net)$" {
  ...
}

Just configure it properly and you're ready to go..

    (1-8/8)