From 7f8383098e49588529e3a203ed6d7bb2f27aef5c Mon Sep 17 00:00:00 2001 From: Fredrik Tolf Date: Wed, 2 Mar 2011 15:17:45 +0100 Subject: [PATCH] Added some simple configuration examples. --- examples/README | 12 ++++++++++++ examples/python/dynhosts/127.0.0.1/index.txt | 1 + examples/python/dynhosts/README | 7 +++++++ examples/python/dynhosts/dynhosts | 23 +++++++++++++++++++++++ examples/python/dynhosts/localhost/index.txt | 1 + examples/python/dynhosts/run | 6 ++++++ examples/static-files/README | 2 ++ examples/static-files/index.html | 17 +++++++++++++++++ examples/static-files/run | 6 ++++++ examples/static-files/test.css | 11 +++++++++++ examples/vhosts/README | 2 ++ examples/vhosts/default-site/index.html | 19 +++++++++++++++++++ examples/vhosts/default-site/test.css | 11 +++++++++++ examples/vhosts/localhost/index.html | 19 +++++++++++++++++++ examples/vhosts/localhost/test.css | 11 +++++++++++ examples/vhosts/patterns.conf | 13 +++++++++++++ examples/vhosts/run | 6 ++++++ 17 files changed, 167 insertions(+) create mode 100644 examples/README create mode 100644 examples/python/dynhosts/127.0.0.1/index.txt create mode 100644 examples/python/dynhosts/README create mode 100755 examples/python/dynhosts/dynhosts create mode 100644 examples/python/dynhosts/localhost/index.txt create mode 100755 examples/python/dynhosts/run create mode 100644 examples/static-files/README create mode 100644 examples/static-files/index.html create mode 100755 examples/static-files/run create mode 100644 examples/static-files/test.css create mode 100644 examples/vhosts/README create mode 100644 examples/vhosts/default-site/index.html create mode 100644 examples/vhosts/default-site/test.css create mode 100644 examples/vhosts/localhost/index.html create mode 100644 examples/vhosts/localhost/test.css create mode 100644 examples/vhosts/patterns.conf create mode 100755 examples/vhosts/run diff --git a/examples/README b/examples/README new file mode 100644 index 0000000..b29ef70 --- /dev/null +++ b/examples/README @@ -0,0 +1,12 @@ +This directory contains some examples of more or less simple ashd +configurations. Each sub-directory contains a self-contained example +with a shell script called `run'. Simply run that script to start the +example, and examine it to see how it was made. All of them will start +an non-SSL HTTP server on port 8080. + +Note that ashd must be installed on the system to be able to run the +examples, including the default configuration files. + +The `python' sub-directory contains examples for using the Python +module. To run then, the Python module has to be installed and +accessible as well. diff --git a/examples/python/dynhosts/127.0.0.1/index.txt b/examples/python/dynhosts/127.0.0.1/index.txt new file mode 100644 index 0000000..e874877 --- /dev/null +++ b/examples/python/dynhosts/127.0.0.1/index.txt @@ -0,0 +1 @@ +You're accessing via IP address. diff --git a/examples/python/dynhosts/README b/examples/python/dynhosts/README new file mode 100644 index 0000000..a7f806e --- /dev/null +++ b/examples/python/dynhosts/README @@ -0,0 +1,7 @@ +This example uses Python to dynamically dispatch requests for +different vhosts. The Python program dynhosts will look in a directory +for subdirectories named after the virtual host and start a dirplex +instance for each such host that is requested. + +To try this example, run it on your local machine and request + or . diff --git a/examples/python/dynhosts/dynhosts b/examples/python/dynhosts/dynhosts new file mode 100755 index 0000000..fae28c8 --- /dev/null +++ b/examples/python/dynhosts/dynhosts @@ -0,0 +1,23 @@ +#!/usr/bin/python + +import os, sys, signal +from ashd import util + +children = {} +root = sys.argv[1] +signal.signal(signal.SIGCHLD, signal.SIG_IGN) + +def serve(req): + if "Host" in req: + # Strip port specification + dname = req["Host"].split(':')[0] + dname = dname.lower() + path = os.path.join(root, dname) + if os.path.isdir(path): + if dname not in children: + children[dname] = util.pchild(["dirplex", path], autorespawn = True) + children[dname].passreq(req) + return + util.respond(req, "No such host in configured.\n", status = "404 Not Found", ctype = "text/plain") + +util.serveloop(serve) diff --git a/examples/python/dynhosts/localhost/index.txt b/examples/python/dynhosts/localhost/index.txt new file mode 100644 index 0000000..e6b86d8 --- /dev/null +++ b/examples/python/dynhosts/localhost/index.txt @@ -0,0 +1 @@ +You're accessing via hostname. diff --git a/examples/python/dynhosts/run b/examples/python/dynhosts/run new file mode 100755 index 0000000..fe81f84 --- /dev/null +++ b/examples/python/dynhosts/run @@ -0,0 +1,6 @@ +#!/bin/sh + +set -e +cd "$(dirname "$0")" + +htparser plain:port=8080 -- setsid ./dynhosts . diff --git a/examples/static-files/README b/examples/static-files/README new file mode 100644 index 0000000..d1987ca --- /dev/null +++ b/examples/static-files/README @@ -0,0 +1,2 @@ +To view this example, simply run it on your local machine and point +your web browser at . diff --git a/examples/static-files/index.html b/examples/static-files/index.html new file mode 100644 index 0000000..0492ddb --- /dev/null +++ b/examples/static-files/index.html @@ -0,0 +1,17 @@ + + + + +Test page + + + +

Test page

+

+Note how this page is accessible as +/, +/index and +/index.html. +

+ + diff --git a/examples/static-files/run b/examples/static-files/run new file mode 100755 index 0000000..f667252 --- /dev/null +++ b/examples/static-files/run @@ -0,0 +1,6 @@ +#!/bin/sh + +set -e +cd "$(dirname "$0")" + +htparser plain:port=8080 -- dirplex . diff --git a/examples/static-files/test.css b/examples/static-files/test.css new file mode 100644 index 0000000..178f96e --- /dev/null +++ b/examples/static-files/test.css @@ -0,0 +1,11 @@ +body { + font-family: sans-serif; +} + +h1 { + font-size: 1.75em; +} + +p { + font-size: 1em; +} diff --git a/examples/vhosts/README b/examples/vhosts/README new file mode 100644 index 0000000..d1987ca --- /dev/null +++ b/examples/vhosts/README @@ -0,0 +1,2 @@ +To view this example, simply run it on your local machine and point +your web browser at . diff --git a/examples/vhosts/default-site/index.html b/examples/vhosts/default-site/index.html new file mode 100644 index 0000000..8f75829 --- /dev/null +++ b/examples/vhosts/default-site/index.html @@ -0,0 +1,19 @@ + + + + +Default site + + + +

Default site

+

+This site is called when the requested Host is not exactly +localhost, such as 127.0.0.1. +

+Try visiting +localhost +instead (and make sure the server is running on your local machine). +

+ + diff --git a/examples/vhosts/default-site/test.css b/examples/vhosts/default-site/test.css new file mode 100644 index 0000000..178f96e --- /dev/null +++ b/examples/vhosts/default-site/test.css @@ -0,0 +1,11 @@ +body { + font-family: sans-serif; +} + +h1 { + font-size: 1.75em; +} + +p { + font-size: 1em; +} diff --git a/examples/vhosts/localhost/index.html b/examples/vhosts/localhost/index.html new file mode 100644 index 0000000..26796c0 --- /dev/null +++ b/examples/vhosts/localhost/index.html @@ -0,0 +1,19 @@ + + + + +localhost site + + + +

localhost site

+

+This site is called when the requested Host is +exactly localhost (plus any port specification). +

+Try requesting the server via a different hostname, such as +127.0.0.1, +instead. +

+ + diff --git a/examples/vhosts/localhost/test.css b/examples/vhosts/localhost/test.css new file mode 100644 index 0000000..178f96e --- /dev/null +++ b/examples/vhosts/localhost/test.css @@ -0,0 +1,11 @@ +body { + font-family: sans-serif; +} + +h1 { + font-size: 1.75em; +} + +p { + font-size: 1em; +} diff --git a/examples/vhosts/patterns.conf b/examples/vhosts/patterns.conf new file mode 100644 index 0000000..552f2d0 --- /dev/null +++ b/examples/vhosts/patterns.conf @@ -0,0 +1,13 @@ +child default + exec dirplex default-site + +child localhost + exec dirplex localhost + +match + default + handler default + +match + header host localhost(:[0-9]+)?$ i + handler localhost diff --git a/examples/vhosts/run b/examples/vhosts/run new file mode 100755 index 0000000..bba9e68 --- /dev/null +++ b/examples/vhosts/run @@ -0,0 +1,6 @@ +#!/bin/sh + +set -e +cd "$(dirname "$0")" + +htparser plain:port=8080 -- patplex patterns.conf -- 2.11.0