Lighttpd
上QQ阅读APP看书,第一时间看更新

Chapter 3. More Virtual Hosting and CGI

In this chapter, we will learn:

  • How to set up virtual hosting
  • How to install MySQL server and configure with Lighttpd modules
  • How to configure SCGI and FastCGI with Lighttpd modules

Suppose that we want to host a lot of sites without restarting Lighttpd whenever a new site comes and goes. Given that all sites share the same configuration, we can do this using the line of mod_*vhost modules. To use them, we may include one of the following lines:

server.modules += ("mod_simple_vhost") # for simple virtual hosting
server.modules += ("mod_evhost") # for extended virtual hosting
server.modules += ("mod_mysqlvhost") # for virtual hosting with a MySQL database

The most basic, but an already usable module is mod_simple_vhost. With this simple virtual hosting solution, all we have to do is to supply a server root for virtual hosting, a default host name, and a document root, like this:

simple-vhost.server-root = "/var/www/vhost/"
simple-vhost.default-host = "myvirtualhost.net"
simple-vhost.document-root = "htdocs"

mod_simple_vhost intercepts each request and constructs a document path out of the server root, the host name (either from the request or the default), the document root, and the file path. Given http://some.virtualhost.net/some/file.html as the request URL, mod_simple_vhost would construct the path as:

"/var/www/vhost"/"some.virtualhost.net"/"htdocs"/"some/file.html"

If the file could not be found, mod_simple_vhost will see if the directory some.virtualhost.net exists in the server root . If so, it will return a file not found error (HTTP code 404). Otherwise, it will not even answer the request, as the domain is obviously not on this server.