/usr/share/doc/python-twisted-web2/howto/tap-deploy.html is in python-twisted-web2 8.1.0-3build1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 | <?xml version="1.0"?><!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" lang="en"><head><title>Twisted Documentation: Twisted.Web2 Deployment with mktap</title><link href="stylesheet.css" type="text/css" rel="stylesheet" /></head><body bgcolor="white"><h1 class="title">Twisted.Web2 Deployment with mktap</h1><div class="toc"><ol><li><a href="#auto0">Simple Servers</a></li><ul><li><a href="#auto1">Static Files</a></li><li><a href="#auto2">Dynamic Resources</a></li></ul><li><a href="#auto3">Virtual Hosts</a></li><ul><li><a href="#auto4">Just a bunch of directories</a></li><li><a href="#auto5">Adding a Single Virtual Host</a></li></ul><li><a href="#auto6">Conclusion</a></li></ol></div><div class="content"><span></span><p>While Twisted.Web2 can be deployed in a variety of flexible and
complicated ways, occasionally a simpler approach is desired. For
this Web2 makes use of TAPs created by the mktap commandline utility.
This document outlines a few of the approaches for creating,
configuring, and deploying a Twisted.Web2 with mktap.</p><p>Since the Web2 mktap plugin is a work in progress it is
suggested that you refer to the output of the following command
for further information</p><pre class="shell">
% mktap web2 --help
</pre><h2>Simple Servers<a name="auto0"></a></h2><h3>Static Files<a name="auto1"></a></h3><p>Perhaps the simplest possible Twisted.Web2 configuration is to
serve a bunch of static files from a directory.</p><pre class="shell">
% mktap web2 --path /some/path
</pre><p>In case you've forgotten mktap 101 this will create a file in
the current directory called web2.tap, you can then launch this
server configuration with the following command.</p><pre class="shell">
% twistd -nf web2
2006/03/02 00:29 PST [-] Log opened.
2006/03/02 00:29 PST [-] twistd SVN-Trunk (/usr/bin/python 2.4.2) starting up
2006/03/02 00:29 PST [-] reactor class: twisted.internet.selectreactor.SelectReactor
2006/03/02 00:29 PST [-] Loading web2.tap...
2006/03/02 00:29 PST [-] Loaded.
2006/03/02 00:29 PST [-] twisted.web2.channel.http.HTTPFactory starting on 8080
2006/03/02 00:29 PST [-] Starting factory <twisted.web2.channel.http.HTTPFactory instance at 0x7787ee4c>
</pre><p>You now have a HTTP server serving static files on port 8080,
and if you open it in a web browser you'll see something like
this in your terminal.</p><pre class="shell">
2006/03/02 00:29 PST [HTTPChannel,0,127.0.0.1] 127.0.0.1 - - [02/Mar/2006:00:29:14 -0700] "GET / HTTP/1.1" 200 2577 "-" "Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.8.0.1) Gecko/20060224 Ubuntu/dapper Firefox/1.5.0.1"
</pre><p>By default the TAP plugin logs to the standard twistd logfile.
However if you specify the <code class="shell">--logfile</code>
option twistd will log to the specified file in the Common Access
Logging format.</p><pre class="shell">
% mktap web2 --path /some/path --logfile ./access.log
</pre><h3>Dynamic Resources<a name="auto2"></a></h3><p>Twisted.Web2's tap plugin is also perfectly capable of serving
up a dynamic Resource or two. In the name of completeness here
is a simple resource.</p><div class="py-listing"><pre>
<span class="py-src-keyword">from</span> <span class="py-src-variable">twisted</span>.<span class="py-src-variable">web2</span> <span class="py-src-keyword">import</span> <span class="py-src-variable">http</span>, <span class="py-src-variable">resource</span>
<span class="py-src-keyword">class</span> <span class="py-src-identifier">HelloWorld</span>(<span class="py-src-parameter">resource</span>.<span class="py-src-parameter">Resource</span>):
<span class="py-src-keyword">def</span> <span class="py-src-identifier">render</span>(<span class="py-src-parameter">self</span>, <span class="py-src-parameter">req</span>):
<span class="py-src-keyword">return</span> <span class="py-src-variable">http</span>.<span class="py-src-variable">Response</span>(<span class="py-src-number">200</span>, <span class="py-src-variable">stream</span>=<span class="py-src-string">"Hello, World!"</span>)
</pre><div class="caption">
Listing 1: Hello World - <a href="../examples/hello.py"><span class="filename">../examples/hello.py</span></a></div></div><p>To use it from mktap you simply have to make sure it's in your
PYTHONPATH and tell mktap to use it as its root resource.</p><pre class="shell">
% mktap web2 --class=hello.HelloWorld
</pre><p>It's important to keep in mind that this class will be created
with no arguments passed to the constructor.</p><h2>Virtual Hosts<a name="auto3"></a></h2><p>Now for something a little different, and a little more
advanced. The TAP plugin supports several ways of configuring a server
that uses Named Virtual Hosting.</p><h3>Just a bunch of directories<a name="auto4"></a></h3><p>The first method of serving virtual hosts involves a bunch of
directories that correspond to the root directory of a virtual
host.</p><p>For example:</p><pre class="shell">
% ls servers
test.example.com
foo.example.com
mail.example.com
% mktap web2 --vhost-path servers/
</pre><p>Each of the directories under <code class="shell">servers</code> is served out as
a <code class="API"><a href="http://twistedmatrix.com/documents/8.1.0/api/twisted.web2.static.File.html" title="twisted.web2.static.File">static.File</a></code> when
you visit the appropriate url, for example
http://test.example.com:8080/ will give you the contents of
<code class="shell">servers/test.example.com</code> (assuming
test.example.com points to the actual place where the server is
running.)
</p><h3>Adding a Single Virtual Host<a name="auto5"></a></h3><p>You can also add a single virtual host at a time, either in
a seperate directory structure with
<code class="shell">--vhost-static</code> or as a dynamic resource
with <code class="shell">--vhost-class</code>. You can use as
many of these arguments as you wish, even combining them with
<code class="shell">--vhost-path</code>.</p><p>For example the following command will give us a web2.tap that
serves two virtual hosts, images.example.com and example.com which
will serve our dynamic application (
<a href="../examples/hello.py" class="py-filename">Hello World</a>.)</p><pre class="shell">
% mktap web2 --vhost-static=images.example.com=images/ --vhost-class=example.com=hello.HelloWorld
</pre><h2>Conclusion<a name="auto6"></a></h2><p>Web2's TAP plugin is a great way to get start a server and start
playing around. However there are many other ways to deploy web2,
and the TAP plugin is meant to be a stepping stone to more advanced
techniques such as those mentioned in the deployment howto.</p></div><p><a href="index.html">Index</a></p><span class="version">Version: 8.1.0</span></body></html>
|