| 2 | | <section xmlns:db="http://docbook.org/docbook-ng" |
|---|
| 3 | | xmlns:xi="http://www.w3.org/2001/XInclude" |
|---|
| 4 | | xmlns:xsl="http://www.w3.org/1999/XSL/Transform" |
|---|
| 5 | | xml:id="configsystemoverview"> |
|---|
| 6 | | <title>Configuration system overview</title> |
|---|
| 7 | | <para>The CherryPy configuration system provides fine-grained control over |
|---|
| 8 | | how each part of the application should react. You will use it for two |
|---|
| 9 | | reasons:</para> |
|---|
| 10 | | <itemizedlist> |
|---|
| 11 | | <listitem>Web server settings</listitem> |
|---|
| 12 | | <listitem>Enabling filters per path</listitem> |
|---|
| 13 | | </itemizedlist> |
|---|
| 14 | | <para>You will be able to declare the configuration settings either from a |
|---|
| 15 | | file or from a Python dictionary.</para> |
|---|
| 16 | | <para>First of all, let's see how a typical configuration file is |
|---|
| 17 | | defined.</para> |
|---|
| 18 | | <example> |
|---|
| 19 | | <title>Configuration file</title> |
|---|
| 20 | | <programlisting linenumbering="numbered"> |
|---|
| | 2 | <section xmlns:db="http://docbook.org/docbook-ng" xmlns:xi="http://www.w3.org/2001/XInclude" |
|---|
| | 3 | xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xml:id="configsystemoverview"> |
|---|
| | 4 | <title>Configuration system</title> |
|---|
| | 5 | <para>The CherryPy configuration system provides fine-grained control over how each part of the |
|---|
| | 6 | application should react. You will use it for two reasons:</para> |
|---|
| | 7 | <itemizedlist> |
|---|
| | 8 | <listitem> |
|---|
| | 9 | <para>Web server settings</para> |
|---|
| | 10 | </listitem> |
|---|
| | 11 | <listitem> |
|---|
| | 12 | <para>Enabling filters per path</para> |
|---|
| | 13 | </listitem> |
|---|
| | 14 | </itemizedlist> |
|---|
| | 15 | <para>You will be able to declare the configuration settings either from a file or from a Python |
|---|
| | 16 | dictionary.</para> |
|---|
| | 17 | <para>First of all, let's see how a typical configuration file is defined.</para> |
|---|
| | 18 | <example> |
|---|
| | 19 | <title>Configuration file</title> |
|---|
| | 20 | <programlisting linenumbering="numbered"> |
|---|
| 79 | | </example> |
|---|
| 80 | | <para>Each section of the configuration refers to a URL path; each path is |
|---|
| 81 | | mapped to a published object of the tree handled by CherryPy. Therefore when |
|---|
| 82 | | the server receives a request for <code>/css/default.css</code>, the static |
|---|
| 83 | | filter will be called and the server will actually return the physical file |
|---|
| 84 | | name <filename>data/css/default.css</filename>.</para> |
|---|
| 85 | | <para>Since the path <code>/service/xmlrpc</code> has the XML-RPC filter |
|---|
| 86 | | enabled, all the exposed methods of the object |
|---|
| 87 | | <code>cherrypy.root.service.xmlrpc</code> will be treated as XML-RPC |
|---|
| 88 | | methods.</para> |
|---|
| 89 | | <para>The root entry, defined as <code>global</code>, is also responsible |
|---|
| 90 | | for defining the server settings such as the port, the protocol version to |
|---|
| 91 | | use by default, the number of threads to start with the server, etc.</para> |
|---|
| 92 | | <para>All values in the configuration file must be valid Python values. |
|---|
| 93 | | Strings must be quoted, booleans must be True or False, etc.</para> |
|---|
| 94 | | <para>The <code>server.environment</code> entry controls how CherryPy should |
|---|
| 95 | | run. Three values are legal:</para> |
|---|
| 96 | | <itemizedlist> |
|---|
| 97 | | <listitem>development <itemizedlist> |
|---|
| 98 | | <listitem>logDebugInfoFilter is enabled by default</listitem> |
|---|
| 99 | | <listitem>HTTPErrors (and therefore the default _cpOnError) display |
|---|
| 100 | | tracebacks in the browser if errors occur</listitem> |
|---|
| 101 | | <listitem>autoreload is enabled by default</listitem> |
|---|
| 102 | | </itemizedlist></listitem> |
|---|
| 103 | | <listitem>production <itemizedlist> |
|---|
| 104 | | <listitem>logDebugInfoFilter is disabled by default</listitem> |
|---|
| 105 | | <listitem> |
|---|
| 106 | | <para>tracebacks are logged, but are not displayed in the |
|---|
| 107 | | browser</para> |
|---|
| 108 | | </listitem> |
|---|
| 109 | | <listitem>autoreload is disabled by default</listitem> |
|---|
| 110 | | </itemizedlist></listitem> |
|---|
| 111 | | <listitem>staging (same as production for the moment)</listitem> |
|---|
| 112 | | </itemizedlist> |
|---|
| | 79 | </example> |
|---|
| | 80 | <section> |
|---|
| | 81 | <title>Configuration Sections</title> |
|---|
| | 82 | <para>Each section of the configuration refers to an object path; the object path is used to |
|---|
| | 83 | lookup the correct handler for each Request-URI. Therefore when the server receives a |
|---|
| | 84 | Request-URI of <code>/css/default.css</code>, the static filter will handle the request, and |
|---|
| | 85 | the server will actually return the physical file at |
|---|
| | 86 | <filename>data/css/default.css</filename>. Since the path <code>/service/xmlrpc</code> has |
|---|
| | 87 | the XML-RPC filter enabled, all the exposed methods of the object |
|---|
| | 88 | <code>cherrypy.root.service.xmlrpc</code> will be treated as XML-RPC methods.</para> |
|---|
| | 89 | <para>The <code>global</code> entry represents settings which apply outside the request |
|---|
| | 90 | process, including server settings such as the port, the protocol version to use by default, |
|---|
| | 91 | the number of threads to start with the server, etc. This is <emphasis>not</emphasis> the |
|---|
| | 92 | same as the root entry <code>[/]</code>, which maps to cherrypy.root.</para> |
|---|
| | 93 | <para>By default, URI's and object paths are equivalent; however, filters may rewrite the |
|---|
| | 94 | objectPath to produce a different mapping between URI's and handlers. This is necessary, for |
|---|
| | 95 | example, when mounting applications at virtual roots (e.g. serving the object path |
|---|
| | 96 | <code>/welcome</code> at the URI "/users/~rdelon/welcome").</para> |
|---|
| | 97 | </section> |
|---|
| | 98 | <section> |
|---|
| | 99 | <title>Configuration Entries</title> |
|---|
| | 100 | <para>All values in the configuration file must be valid Python values. Strings must be |
|---|
| | 101 | quoted, booleans must be True or False, etc.</para> |
|---|
| | 102 | <section> |
|---|
| | 103 | <title>server.environment</title> |
|---|
| | 104 | <para>The <code>server.environment</code> entry controls how CherryPy should run. Three |
|---|
| | 105 | values are built in:</para> |
|---|
| | 106 | <itemizedlist> |
|---|
| | 107 | <listitem> |
|---|
| | 108 | <para>development</para> |
|---|
| | 109 | <itemizedlist> |
|---|
| | 110 | <listitem> |
|---|
| | 111 | <para>logDebugInfoFilter is enabled</para> |
|---|
| | 112 | </listitem> |
|---|
| | 113 | <listitem> |
|---|
| | 114 | <para>HTTPErrors (and therefore the default _cpOnError) display |
|---|
| | 115 | tracebacks in the browser if errors occur</para> |
|---|
| | 116 | </listitem> |
|---|
| | 117 | <listitem> |
|---|
| | 118 | <para>autoreload is enabled</para> |
|---|
| | 119 | </listitem> |
|---|
| | 120 | <listitem> |
|---|
| | 121 | <para>NotFound errors (404) are listed in the error.log</para> |
|---|
| | 122 | </listitem> |
|---|
| | 123 | </itemizedlist> |
|---|
| | 124 | </listitem> |
|---|
| | 125 | <listitem> |
|---|
| | 126 | <para>production</para> |
|---|
| | 127 | <itemizedlist> |
|---|
| | 128 | <listitem> |
|---|
| | 129 | <para>logDebugInfoFilter is disabled</para> |
|---|
| | 130 | </listitem> |
|---|
| | 131 | <listitem> |
|---|
| | 132 | <para>tracebacks are logged, but are not displayed in the browser</para> |
|---|
| | 133 | </listitem> |
|---|
| | 134 | <listitem> |
|---|
| | 135 | <para>autoreload is disabled</para> |
|---|
| | 136 | </listitem> |
|---|
| | 137 | <listitem> |
|---|
| | 138 | <para>NotFound errors (404) aren't listed in the error log</para> |
|---|
| | 139 | </listitem> |
|---|
| | 140 | </itemizedlist> |
|---|
| | 141 | </listitem> |
|---|
| | 142 | <listitem> |
|---|
| | 143 | <para>staging (same as production for the moment)</para> |
|---|
| | 144 | </listitem> |
|---|
| | 145 | </itemizedlist> |
|---|
| | 146 | <para>Beginning in CherryPy 2.2, the behavior of each environment is defined in |
|---|
| | 147 | <code>cherrypy.config.environments</code>, a dict whose keys are "development", |
|---|
| | 148 | "production", etc, and whose values are dicts of config keys and values. Application |
|---|
| | 149 | developers are free to modify existing environments, or define new environments for use |
|---|
| | 150 | by their deployers, by modifying this container. For example, if you develop an |
|---|
| | 151 | application which absolutely cannot handle autoreload, your app can set |
|---|
| | 152 | <code>cherrypy.config.environments['development']['autoreload.on'] = False</code>. |
|---|
| | 153 | Deployers who selected the "development" environment would then be free from the danger |
|---|
| | 154 | of autoreload interacting with your application. Another example of using |
|---|
| | 155 | config.environments directly might be an application which needs a "development" and |
|---|
| | 156 | "production" environment, but also separate "beta", "rc", "live data" and/or "testing" |
|---|
| | 157 | environments.</para> |
|---|
| | 158 | </section> |
|---|
| | 159 | </section> |
|---|