<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <head> <meta http-equiv="Content-type" content="text/html; charset=utf-8" /> <meta http-equiv="Content-Language" content="en-us" /> <meta name="ROBOTS" content="ALL" /> <meta http-equiv="imagetoolbar" content="no" /> <meta name="MSSmartTagsPreventParsing" content="true" /> <meta name="Keywords" content="cherokee web server httpd http" /> <meta name="Description" content="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." /> <link href="media/css/cherokee_doc.css" rel="stylesheet" type="text/css" media="all" /> </head> <body> <h2 id="_a_href_index_html_index_a_8594_a_href_config_html_configuration_a_8594_a_href_config_virtual_servers_html_virtual_servers_a"><a href="index.html">Index</a> → <a href="config.html">Configuration</a> → <a href="config_virtual_servers.html">Virtual servers</a></h2> <div class="sectionbody"> </div> <h2 id="_advanced_virtual_hosting">Advanced Virtual Hosting</h2> <div class="sectionbody"> <div class="paragraph"><p>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.</p></div> <div class="imageblock"> <div class="content"> <img src="media/images/admin_vserver_evhost.png" alt="media/images/admin_vserver_evhost.png" /> </div> </div> <div class="paragraph"><p>The following replacement variables are supported. Let’s suppose a request to the <tt>alo.users.example.com</tt> domain for the examples:</p></div> <div class="tableblock"> <table rules="all" width="100%" frame="border" cellspacing="0" cellpadding="4"> <col width="33%" /> <col width="33%" /> <col width="33%" /> <thead> <tr> <th align="left" valign="top">Variable </th> <th align="left" valign="top">Example </th> <th align="left" valign="top">Description</th> </tr> </thead> <tbody> <tr> <td align="left" valign="top"><p class="table"><tt>${domain}</tt></p></td> <td align="left" valign="top"><p class="table">alo.users.example.com</p></td> <td align="left" valign="top"><p class="table">Full domain name</p></td> </tr> <tr> <td align="left" valign="top"><p class="table"><tt>${tld}</tt></p></td> <td align="left" valign="top"><p class="table">com</p></td> <td align="left" valign="top"><p class="table">Top Level Domain</p></td> </tr> <tr> <td align="left" valign="top"><p class="table"><tt>${domain_no_tld}</tt></p></td> <td align="left" valign="top"><p class="table">alo.users.example</p></td> <td align="left" valign="top"><p class="table">Domain without the TLD</p></td> </tr> <tr> <td align="left" valign="top"><p class="table"><tt>${subdomain1}</tt></p></td> <td align="left" valign="top"><p class="table">users</p></td> <td align="left" valign="top"><p class="table">First sub-domain</p></td> </tr> <tr> <td align="left" valign="top"><p class="table"><tt>${subdomain2}</tt></p></td> <td align="left" valign="top"><p class="table">alo</p></td> <td align="left" valign="top"><p class="table">Second sub-domain</p></td> </tr> </tbody> </table> </div> <h3 id="slicing">Slicing</h3><div style="clear:left"></div> <div class="paragraph"><p>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.</p></div> <div class="paragraph"><p>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.</p></div> <div class="paragraph"><p>If you are not familiar with the Python syntax, these are the rules:</p></div> <div class="olist arabic"><ol class="arabic"> <li> <p> For any given <tt>string</tt>, a slice is denoted as <tt>string[x:y]</tt> </p> </li> <li> <p> Indices start at 0, and [x:y] denotes a range comprehending from index x (included) to index y (excluded). </p> </li> <li> <p> 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. </p> </li> </ol></div> <div class="paragraph"><p>It is pretty straight forward. Here are some examples:</p></div> <div class="tableblock"> <table rules="all" width="100%" frame="border" cellspacing="0" cellpadding="4"> <col width="50%" /> <col width="50%" /> <thead> <tr> <th align="left" valign="top">Variable </th> <th align="left" valign="top">Explanation</th> </tr> </thead> <tbody> <tr> <td align="left" valign="top"><p class="table"><tt>${domain}[:1]</tt></p></td> <td align="left" valign="top"><p class="table">From the beginning of the string until the character at index <tt>1</tt> (not included)</p></td> </tr> <tr> <td align="left" valign="top"><p class="table"><tt>${domain}[1:2]</tt></p></td> <td align="left" valign="top"><p class="table">From index <tt>1</tt> (included), to index <tt>2</tt> (not included)</p></td> </tr> <tr> <td align="left" valign="top"><p class="table"><tt>${domain}[:-1]</tt></p></td> <td align="left" valign="top"><p class="table">From the beginning of the string until the last character (not included). Since <tt>0</tt> is the first character, counting backwards one element would be the last element of the string.</p></td> </tr> </tbody> </table> </div> <div class="paragraph"><p>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:</p></div> <div class="listingblock"> <div class="content"> <pre><tt> /var/www/e/x/example.com /var/www/c/h/cherokee-project.com /var/www/1/2/12345.com</tt></pre> </div></div> <div class="paragraph"><p>The "Advanced Virtual Hosting" supports this type of set-up by using</p></div> <div class="listingblock"> <div class="content"> <pre><tt> /var/www/${domain}[:1]/${domain}[1:2]/${domain}</tt></pre> </div></div> </div> <div id="footer"> <div id="footer-text"> </div> </div> </body> </html>