/usr/share/doc/python-myghty/html/configuration.html is in python-myghty 1.1-6.
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 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 | <html>
<head>
<title>
Myghty Documentation
</title>
<link href="style.css" rel="stylesheet" type="text/css"></link>
<link href="syntaxhighlight.css" rel="stylesheet" type="text/css"></link>
</head>
<body>
<link href="docs.css" rel="stylesheet" type="text/css"></link>
<div style="position:absolute;left:0px;top:0px;"><a name="top"></a> </div>
<div class="doccontainer">
<div class="docheader">
<div class="docheadertext" >Myghty Documentation</div>
<div class="">Version: 1.1 Last Updated: 09/10/06 19:32:29</div>
</div>
<A name="configuration"></a>
<div class="topnav">
<div class="topnavcontrol">
View: <b>Paged</b> | <a href="documentation.html">One Page</a>
</div>
<div class="topnavsectionlink">
<a href="index.html">Table of Contents</a>
<div class="prevnext">
Previous: <a href="installation.html">Installation</a>
|
Next: <a href="programmatic.html">Programmatic Configuration</a>
</div>
</div>
<div class="topnavmain">
<div class="topnavheader">Configuration</div>
<div class="topnavitems">
<div class="toclink">
<A style="" href="#configuration_standalone">Standalone Handler</a>
</div>
<div class="toclinkcontainer">
</div>
<div class="toclink">
<A style="" href="#configuration_cgi">CGI</a>
</div>
<div class="toclinkcontainer">
</div>
<div class="toclink">
<A style="" href="#configuration_mod_python">mod_python</a>
</div>
<div class="toclinkcontainer">
<div class="toclinkcontainer">
<div class="smalltoclink">
<A href="#configuration_mod_python_multiple">Advanced mod_python Configuration - Multiple ApacheHandlers</a>
</div>
</div>
</div>
</div>
</div>
</div>
<div class="sectioncontent">
<div class="subsection" style="margin-left:10px;">
<div class="sectiontext">
<p>Below are configuration instructions for the three most basic types of configuration: the standalone handler, a CGI handler, and running under mod_python. For further information on configuration, see:
<ul>
<li><a href="http://www.myghty.org/trac/wiki/How-to%27s_Configuration">How-to's_Configuration</a> - User-contributed configuration information at www.myghty.org, including:
<ul>
<li><a href="http://www.myghty.org/trac/wiki/How_to_Configure_lighttpd_%2B_mod_fastcgi_%2B_Myghty">How to Configure lighttpd + mod fastcgi + Myghty</a> - A configuration that one user acheives six times faster performance than an equivalent Apache configuration.
</ul>
</li>
<li><a href="params.html#parameters" >Index of Configuration Parameters</a> - full index of configuration parameters</li>
<li><a href="programmatic.html#configuration_programmatic" >Programmatic Configuration</a> - writing Python modules that interface to Myghty in various ways</li>
<li><a href="resolver.html#resolver" >Advanced Resolver Configuration</a> - developing custom rulesets to match URIs to components</li>
<li><a href="cache.html#caching_options" >Cache Options</a> - configuring component-caching support</li>
<li><a href="session.html#session_options" >Session Options</a> - configuring session-storage support</li>
</ul>
</p>
</div>
<A name="configuration_standalone"></a>
<div class="subsection" style="margin-left:20px;">
<span class="sectionheadertext">Standalone Handler</span>
<div class="sectiontext">
<p>The standalone handler is a web server built off of Python's BaseHTTPServer class, and is great for local workstation development and testing. Here is a quick example to simply serve pages from the current directory - place the following code into a file <span class="codeline">run_server.py</span>:</p>
<div class="code">
<pre><span class="python_comment">#!/usr/local/bin/python</span>
<span class="python_keyword">import </span><span class="python_name">myghty</span><span class="python_operator">.</span><span class="python_name">http</span><span class="python_operator">.</span><span class="python_name">HTTPServerHandler </span><span class="python_keyword">as </span><span class="python_name">HTTPServerHandler</span><span class="python_operator">
</span>
<span class="python_comment"># create the server.</span>
<span class="python_name">httpd </span><span class="python_operator">= </span><span class="python_name">HTTPServerHandler</span><span class="python_operator">.</span><span class="python_name">HTTPServer</span><span class="python_enclosure">(</span>
<span class="python_comment"># port number to listen on.</span>
<span class="python_name">port </span><span class="python_operator">= </span><span class="python_number">8080</span><span class="python_operator">,</span>
<span class="python_comment"># HSHandler list. indicates paths where the file should be interpreted</span>
<span class="python_comment"># as a Myghty component request.</span>
<span class="python_comment"># Format is a list of dictionaries, each maps a regular expression matching a URI</span>
<span class="python_comment"># to an instance of HTTPServerHandler.HSHandler, containing the arguments for</span>
<span class="python_comment"># a Myghty interprter. for HTTP requests of type "text/*", this list is matched</span>
<span class="python_comment"># first against the incoming request URI. </span>
<span class="python_name">handlers </span><span class="python_operator">= </span><span class="python_enclosure">[</span>
<span class="python_enclosure">{</span><span class="python_literal">'.*\.myt' </span><span class="python_operator">: </span><span class="python_name">HTTPServerHandler</span><span class="python_operator">.</span><span class="python_name">HSHandler</span><span class="python_enclosure">(</span><span class="python_name">data_dir </span><span class="python_operator">= </span><span class="python_literal">'./cache'</span><span class="python_operator">, </span><span class="python_name">component_root </span><span class="python_operator">= </span><span class="python_literal">'./'</span><span class="python_enclosure">)}</span><span class="python_operator">,</span>
<span class="python_enclosure">]</span><span class="python_operator">,</span>
<span class="python_comment"># document root list. indicates paths where the file should be served</span>
<span class="python_comment"># like a normal file, with the appropriate MIME type set as the content-type.</span>
<span class="python_comment"># These are served for all non "text/*" HTTP requests, and all</span>
<span class="python_comment"># incoming URIs that do not match the list of handlers above.</span>
<span class="python_name">docroot </span><span class="python_operator">= </span><span class="python_enclosure">[{</span><span class="python_literal">'.*' </span><span class="python_operator">: </span><span class="python_literal">'./'</span><span class="python_enclosure">}]</span><span class="python_operator">,</span>
<span class="python_enclosure">) </span><span class="python_operator">
</span>
<span class="python_comment"># run the server</span>
<span class="python_name">httpd</span><span class="python_operator">.</span><span class="python_name">serve_forever</span><span class="python_enclosure">()</span><span class="python_operator"></span></pre></div>
<p>Then, in that same directory, place another file, called <span class="codeline">index.myt</span>:</p>
<div class="code">
<pre><span class="text"><html>
<head><title>Test Page</title></head>
<body>
Welcome to Myghty !
</body>
</html></span></pre></div>
<p>To run the server, type:</p>
<div class="code">
<pre>python ./run_server.py</pre></div>
<p>and point a web browser to <span class="codeline">http://localhost:8080/index.myt</span>. The data directory <span class="codeline">./cache</span> will be automatically created to store data files.</p>
<p>Other examples of the Standalone handler are available in <span class="codeline">examples/shoppingcart/run_cart.py</span> for a straightforward example, or <span class="codeline">tools/run_docs.py</span> for an advanced example that also makes use of custom resolution strategies.</p>
</div>
<a href="#configuration" class="toclink">back to section top</a>
</div>
<A name="configuration_cgi"></a>
<div class="subsection" style="margin-left:20px;">
<span class="sectionheadertext">CGI</span>
<div class="sectiontext">
<p>Serving Myghty template files directly via CGI can be achieved with the <span class="codeline">myghty.cgi</span> utility located in the <span class="codeline">/tools</span> directory. This program is a simple interface to the <span class="codeline">CGIHandler</span>, which converts the "path-info" of the requested URI into a Myghty component call. The script's configuration information is present within the top half of the script itself, to allow the most straightforward configuration, although it could certainly be modified to load configuration information from any other source such as other Python modules or configuration files.</p>
<p>It requires configuration of the component root, data directory, and optionally additional Python libraries to run. Other configuration parameters can be added to the <span class="codeline">handle()</span> call as well. The cgi handler will handle requests of the form:<br/><br/>
<span class="codeline">http://<domain>/<cgi-bin directory>/myghty.cgi/<uri of template></span>.
</p>
<p>The script is below. Modify the appropriate lines and copy the myghty.cgi program into your webserver's cgi-bin directory for a basic cgi-based template handler. For usage within custom CGI scripts, see the next section detailing programmatic methods of calling Myghty.</p>
<div class="code">
<pre><span class="python_comment">#!/usr/local/bin/python</span>
<span class="python_comment"># myghty cgi runner. place in cgi-bin directory and address Myghty templates</span>
<span class="python_comment"># with URLs in the form:</span>
<span class="python_comment"># http://mysite.com/cgi-bin/myghty.cgi/path/to/template.myt</span>
<span class="python_comment"># component root. this is where the Myghty templates are.</span>
<span class="python_name">component_root </span><span class="python_operator">= </span><span class="python_literal">'/path/to/croot'</span><span class="python_operator">
</span>
<span class="python_comment"># data directory. this is where Myghty puts its object files.</span>
<span class="python_name">data_dir </span><span class="python_operator">= </span><span class="python_literal">'/path/to/datadir'</span><span class="python_operator">
</span>
<span class="python_comment"># libraries. Put paths to additional custom Python libraries here.</span>
<span class="python_name">lib </span><span class="python_operator">= </span><span class="python_enclosure">[</span><span class="python_literal">'/path/to/custom/libraries'</span><span class="python_enclosure">]</span><span class="python_operator">
</span>
<span class="python_keyword">import </span><span class="python_name">sys</span><span class="python_operator">
</span><span class="python_enclosure">[</span><span class="python_name">sys</span><span class="python_operator">.</span><span class="python_name">path</span><span class="python_operator">.</span><span class="python_name">append</span><span class="python_enclosure">(</span><span class="python_name">path</span><span class="python_enclosure">) </span><span class="python_keyword">for </span><span class="python_name">path </span><span class="python_keyword">in </span><span class="python_name">lib</span><span class="python_enclosure">]</span><span class="python_operator">
</span>
<span class="python_keyword">import </span><span class="python_name">myghty</span><span class="python_operator">.</span><span class="python_name">http</span><span class="python_operator">.</span><span class="python_name">CGIHandler </span><span class="python_keyword">as </span><span class="python_name">handler</span><span class="python_operator">
</span>
<span class="python_name">handler</span><span class="python_operator">.</span><span class="python_name">handle</span><span class="python_enclosure">(</span><span class="python_name">component_root</span><span class="python_operator">=</span><span class="python_name">component_root</span><span class="python_operator">, </span><span class="python_name">data_dir</span><span class="python_operator">=</span><span class="python_name">data_dir</span><span class="python_enclosure">)</span><span class="python_operator"></span></pre></div>
</div>
<a href="#configuration" class="toclink">back to section top</a>
</div>
<A name="configuration_mod_python"></a>
<div class="subsection" style="margin-left:20px;">
<span class="sectionheadertext">mod_python</span>
<div class="sectiontext">
<p>This section assumes familiarity with basic Apache configuration. Myghty includes a handler known as <span class="codeline">myghty.http.ApacheHandler</span> which can interpret requests from the mod_python request object. This handler can be configured directly within the httpd.conf file of Apache, using regular Apache configuration file directives to configure its options. Alternatively, the ApacheHandler can be used within an external Python module that defines its own mod_python handler, which allows most of the configuration of the handler to be stated within a Python file instead of the httpd.conf file. The first method, described in this section, is expedient for a straightforward Myghty template service, or a simple view-controller setup. While the full range of configurational options can be present directly in http.conf stated as Apache configuration directives, including Python imports, functions, and datastructures, the syntax of embedding Python into conf directives can quickly become burdensome when configuring an application with a complex resolution stream. Therefore it is recommended that Apache users also become familiar with programmatic configuration, described in the section <a href="programmatic.html#configuration_programmatic_httphandler_ApacheHandler" >ApacheHandler</a>.</p>
<p>Myghty configuration parameters are written in the Apache httpd.conf file as "Myghty" plus the parameter name in InitialCaps. The full range of configuration parameters in <b>None</b> may be used. The values (right-hand side of the configuration directive) are Python evaluable expressions. In the simplest case, this is just a string, which is mostly easily identified as <span class="codeline">r"<string>"</span> so that Apache does not strip the quotes out. Any Python structure can be used as the value, such as a list, dictionary, lambda, etc., as long as the proper Apache conf escaping is used.</p>
<p>Below is a straightforward example that routes all Apache requests for files with the extension ".myt" to the Myghty ApacheHandler:</p>
<div class="code">
<pre># associate .myt files with mod_python
# mod_python 3.1 uses 'mod_python'
AddHandler mod_python .myt
# or for mod_python 2.7 use 'python-program'
# AddHandler python-program .myt
# set the handler called by mod_python to be the Myghty ApacheHandler
PythonHandler myghty.ApacheHandler::handle
# set python library paths - this line is used to indicate
# additional user-defined library paths. this path is not required for the
# Myghty templates themselves.
PythonPath "sys.path+[r'/path/to/my/libraries']"
# set component root.
# for this example, an incoming URL of http://mysite.com/files/myfile.myt
# will be resolved as: /path/to/htdocs/files/myfile.myt
PythonOption MyghtyComponentRoot r"/path/to/htdocs"
# data directory where myghty will write its object files,
# as well as session, cache, and lock files
PythonOption MyghtyDataDir r"/path/to/writeable/data/directory/"
# other options - simply write as 'Myghty' with the param name in
# InitialCaps format, values should be legal python expressions
# watch out for using quotes "" as apache.conf removes them -
# use r"value" or '"value"' instead
PythonOption Myghty<paramname> <paramvalue></pre></div>
<p>When this is done, requests to Apache which refer to pages with the extension .myt will be routed to the ApacheHandler, which will resolve the filename into a component which is then executed.</p>
<p>An additional format for the "MyghtyComponentRoot" parameter, a list of multiple paths, can be specified as a list of dictionaries. An example:
<div class="code">
<pre># Multiple Roots, each has a key to identify it,
# and their ordering determines their precedence
PythonOption MyghtyComponentRoot \
"[ \
{'components':'/optional/path/to/components'}, \
{'main':'/path/to/htdocs/htdocs'} \
]"</pre></div>
<p>
Keep in mind that the MyghtyComponentRoot parameter (normally called component_root) defines filesystem paths that have no relationship to Apache DocumentRoots. From the perspective of Apache, there is only a single mod_python handler being invoked, and it has no awareness of the component_root. This means that any incoming URL which matches the Myghty handler will be matched to a root in the component_root and served as a Myghty template, effectively allowing "access" to files that are not directly access-controlled by Apache. To restrict direct access to Myghty component files which are meant for internal use, an alternate file extension, such as ".myc" can be used, so that while a Myghty component can internally find those files within the component_root, the Apache server has no knowledge of the .myc extension and they are not served. This also requires that the .myc files are kept in a directory or directories separate from any configured Apache DocuementRoots.</p>
<p>
Myghty also has the ability to handle directory requests and requests for nonexistent files via various mechanisms, including <a href="specialtempl.html#specialtempl_dhandler" >dhandler</a> and <a href="modulecomponents.html#modulecomponents" >Module Components</a>. However, the example above is configured to only respond to URLs with the specific file extension of ".myt". To handle directory requests without a filename being present, or requests for many different file extensions at once, replace the usage of <span class="codeline">AddHandler</span> with the Apache <span class="codeline">SetHandler</span> directive combined with the <FilesMatch>, <LocationMatch>, or <DirectoryMatch> Apache directives. These directives are described in the Apache documentation. For example:
</p>
<div class="code">
<pre><LocationMatch '/store/.*'>
SetHandler mod_python
PythonHandler myghty.ApacheHandler::handle
PythonPath "sys.path+[r'/path/to/my/libraries']"
# module component directive. matches regular expressions to Python classes and functions.
PythonOption MyghtyModuleComponents "[ \
{'/store/product/.*':store:ProductHandler},\
{'/store/checkout/.*':store:CheckoutHandler},\
]"
PythonOption MyghtyComponentRoot r"/path/to/htdocs"
PythonOption MyghtyDataDir r"/path/to/writeable/data/directory/"
</LocationMatch></pre></div>
<p>The above MyghtyModuleComponents, the apache version of <a href="params.html#parameters_module_components" >module_components</a>, is just one way to serve module components; there is also <a href="params.html#parameters_module_root" >module_root</a>, as well as the Routes resolver.</p>
<p>When serving all files within a directory, one should take care that Myghty is not be used to handle binary files, such as images. Also, it might be inappropriate to serve other kinds of text files such as stylesheets (.css files) and javascript files (.js files), even though one could use Myghty templating to serve these. To get around these issues, when straight file-extension matching is not enough, the Myghty and non-Myghty files can be placed in different directories and Apache correspondingly configured to enable Python handling in the Myghty directory only.
</p>
</div>
<A name="configuration_mod_python_multiple"></a>
<div class="subsection" style="margin-left:30px;">
<span class="sectionheadertext">Advanced mod_python Configuration - Multiple ApacheHandlers</span>
<div class="sectiontext">
<p>Several Interpreters can be configured with their own set of configuration parameters and executed all within the same Python interpreter instance, through the use of the <a href="params.html#parameters_interpreter_name" >interpreter_name</a> configuration parameter.
In the example below, a site configures three main dynamic areas: a documentation section, a catalog section, and the default section for all requests that do not correspond to the previous two. It uses three ApacheHandlers each with different component_root configuration parameters, but they share a common data_dir. The handlers are each configured inside a <LocationMatch> directive where they are given a unique name that identifies them upon each request.</p>
<div class="code">
<pre># Apache resolves the LocationMatch directives in the order they
# appear so the most general directive is last.
# note that every path within each "component root" parameter has a unique name, since
# all the Myghty interpreters happen to be using the same data directory.
# also, the PythonPath is set for each SetHandler. while this should work as a single
# configuration for all three sections, in testing it seems to work sporadically, so its
# set explicitly for each one.
# set Myghty data dir, will be used by all sub-directives
PythonOption MyghtyDataDir r"/web/myapp/cache/"
# '/docs/', serves product documentation
<LocationMatch "/docs/.*\.myt">
# set myghty handler
SetHandler mod_python
PythonHandler myghty.ApacheHandler::handle
PythonPath "['/foo/bar/lib', '/usr/local/myapp/lib'] + sys.path"
# set interpreter name
PythonOption MyghtyInterpreterName r"document_interp"
# set component root
PythonOption MyghtyComponentRoot "[\
{'docs_components' : r'/web/myapp/components'},\
{'docs_htdocs' : r'/web/myapp/documents'},\
]"
# add a translation rule to trim off the /docs/
# when resolving the component
PythonOption MyghtyPathTranslate "[\
(r'/docs/(.*)' : r'\1'),\
]"
</LocationMatch>
# '/catalog/', serves a browseable catalog via a module component
# users can also log in to this area
<LocationMatch "/catalog/.*">
# set myghty handler
SetHandler mod_python
PythonHandler myghty.ApacheHandler::handle
PythonPath "['/foo/bar/lib', '/usr/local/myapp/lib'] + sys.path"
# set interpreter name
PythonOption MyghtyInterpreterName r"catalog_interp"
# set component root
PythonOption MyghtyComponentRoot "[\
{'catalog_components' : r'/web/myapp/catalog/comp'},\
]"
# configure some module components
PythonOption MyghtyModuleComponents "[\
{r'/catalog/login' : 'myapp.components:Login'},\
{r'/catalog/.*' : 'myapp.components:Catalog'},\
]"
</LocationMatch>
# default: all other site docs
<LocationMatch ".*\.myt">
# set myghty handler
SetHandler mod_python
PythonHandler myghty.ApacheHandler::handle
PythonPath "['/foo/bar/lib', '/usr/local/myapp/lib'] + sys.path"
PythonOption MyghtyInterpreterName r"default_interp"
# set component root
PythonOption MyghtyComponentRoot "[\
{'default' : r'/web/myapp/htdocs'},\
]"
</LocationMatch></pre></div>
<p>Configuring component roots and path translation based on the incoming URI can also be accomplished within the scope of a single Interpreter by defining a custom set of resolver rules. This technique is described in <a href="resolver.html#resolver" >Advanced Resolver Configuration</a>.</p>
</div>
<a href="#configuration" class="toclink">back to section top</a>
</div>
</div>
<div class="sectionnavblock">
<div class="sectionnav">
Previous: <a href="installation.html">Installation</a>
|
Next: <a href="programmatic.html">Programmatic Configuration</a>
</div>
</div>
</div>
</div>
</div>
<center>
</center>
</body>
</html>
|