Toadhttpd

Artifact Content
Login

Artifact f1129e8fe6e7be40c587801915ce25503b50e207946185df4623504c642476a3:

Wiki page [Configuration] by hypnotoad 2018-05-03 21:42:34.
D 2018-05-03T21:42:34.984
L Configuration
P af78a1b6446d2dc82813ee0f419ae2f21b423e1570eaa6f3d383a11bfacef36a
U hypnotoad
W 3375
[Deploying] | Configuration | [Customizing]
<h1>Configuring Toadhttpd</h1>
Toadhttpd will accept all of the same command line options as the httpd example from tcllib. 
<p>
In addition it provides the following default behaviors:
<ul>
<li> If the file <b>config.tcl</b> is present in adjacent to httpd.tcl, it is read in as if the <b>configuration_file</b> paramter was given on the command line.
<li> If the directory <b>htdocs</b> is present in the folder that contains the <b>configuration_file</b> it is assumed to be the value for <b>doc_root</b> (if one is not given either on the command line or in the config file.)
<li> If the directory <b>log</b> is present in the folder that contains the <b>configuration_file</b> it is assumed to be the value for <b>logdir</b> (if one is not given either on the command line or in the config file.)
</ul>

<h2>configuration_file (config.tcl)</h2>
The <b>configuration_file</b> is source by the new <b>httpd::server</b> instance prior to invoking the <b>start</b> method. Because it is sourced by the object itself, you can exercise all of the object's methods via the <b>my</b> mechanism.

<b>etoyoc.com</b> is probably as complicated a setup as one will encounter in the wild. It serves a number of top level domains, mixes static content and dynamic content, and even plays dispatcher to scgi based fossil repositories. On the page [Etoyoc.com] we will explore, in depth, how Sean configured etoyoc.com and how you can do the same to create your own site. For now here is a simple setup to give you a sense of what is in the file:

<verbatim>
# Set a configuration parameter for the server
my config set doc_ttl 900

# Load a plugin
package require toadhttpd::sqlite
package require toadhttpd::bouncer
package require toadhttpd::fossil

##
# Inject a plugin behavior into the server object
##
my plugin bouncer
my plugin sqlite

###
# Specify how URLs are responded to
###
# Someone asking for /ccvv is up to no good, send them to the honeypot
my uri add % /ccvv {
  mixin toadhttpd::content.honeypot
}

###
# If someone asks for http://fossil.etoyoc.com/index* send them to the 
# proper URL
# NOTE: This rule only applies if the server requested was fossil.etoyoc.com
###
my uri add fossil.etoyoc.com {/fossil/ /fossil/index%} {
   mixinmap {reply httpd::content.redirect}
  LOCATION http://fossil.etoyoc.com/fossil
}
# The page /fossil is a dynamic page with a list of fossil repos
my uri add fossil.etoyoc.com /fossil {
   mixinmap {reply toadhttpd::content.fossil_root}
   fossil_root /opt/fossil
   prefix fossil
 }
# Everything under that page is dispatched out to fossil SCGI
# proxies
my uri add fossil.etoyoc.com /fossil/% {
    mixinmap {reply toadhttpd::content.fossil_node_scgi}
    prefix fossil
    fossil_root /opt/fossil
 }

# The "trivial" plugin provides a cute little
# database or random facts. Accept requests at either
# /trivia or /fortune
my uri add % {/trivia /fortune} {
  mixinmap {
    reply ::etoyoc::content.trivia
    style ::etoyoc::style
  }
}
# Add /trivia to the list of places we don't like 
# robots visiting
my robots.txt add /trivia

###
# Note that any URL that hasn't matched one of the rules
# above will be handled by the default hander: find the file
# under doc_root, or fail with 404
###
</verbatim>
Z b8e6bbbf3ac0fe937e2311a9324040d0