Description: Cherokee is a flexible, very fast, lightweight Web server. It is implemented entirely in C, and has no dependencies beyond a standard C library. It is embeddable and extensible with plug-ins. It supports on-the-fly configuration by reading files or strings, TLS/SSL (via GNUTLS or OpenSSL), virtual hosts, authentication, cache friendly features, PHP, custom error management, and much more.
Keywords: cherokee web server httpd http

## Index → Configuration → Virtual servers

## Advanced Virtual Hosting

Cherokee currently support a mechanism by which a single virtual server can handle many different domains. The document root of this virtual server is built dynamically, so even if the domains share a common configuration they can use a number of different Document Root directories.

The following replacement variables are supported. Let’s suppose a request to the `alo.users.example.com` domain for the examples:

Variable | Example | Description
--- | --- | ---
`${domain}` | alo.users.example.com | Full domain name
`${tld}` | com | Top Level Domain
`${domain_no_tld}` | alo.users.example | Domain without the TLD
`${subdomain1}` | users | First sub-domain
`${subdomain2}` | alo | Second sub-domain

### Slicing

The template subsystem is sophisticated enough to provide slicing support, with a grammar that is heavily inspired in the Python syntax. It supports positive and negative indexes, and the omission of one of the index numbers.

This basically allows to define partial replacements for any of the supported variables, meaning that a portion of the replacement string can be used instead of the whole string.

If you are not familiar with the Python syntax, these are the rules:

1. For any given `string`, a slice is denoted as `string[x:y]`

2. Indices start at 0, and [x:y] denotes a range comprehending from index x (included) to index y (excluded).

3. If negative indices are used, the count starts backwards from the last element, meaning -1 will be the last, -2 will be the previous one and so on.

It is pretty straight forward. Here are some examples:

Variable | Explanation
--- | ---
`${domain}[:1]` | From the beginning of the string until the character at index `1` (not included)
`${domain}[1:2]` | From index `1` (included), to index `2` (not included)
`${domain}[:-1]` | From the beginning of the string until the last character (not included). Since `0` is the first character, counting backwards one element would be the last element of the string.

As a practical usage example, we will suppose a scenario where thousands of virtual servers are distributed within a two-level directory tree in order to speed things up. Something like:

      /var/www/e/x/example.com
      /var/www/c/h/cherokee-project.com
      /var/www/1/2/12345.com

The "Advanced Virtual Hosting" supports this type of set-up by using

      /var/www/${domain}[:1]/${domain}[1:2]/${domain}