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
|
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title>12. Configuring CherryPy</title>
<META NAME="description" CONTENT="12. Configuring CherryPy">
<META NAME="keywords" CONTENT="tut">
<META NAME="resource-type" CONTENT="document">
<META NAME="distribution" CONTENT="global">
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<link rel="STYLESHEET" href="tut.css" type='text/css'>
<link rel="first" href="tut.html">
<link rel="contents" href="contents.html" title="Contents">
<LINK REL="next" HREF="node15.html">
<LINK REL="previous" HREF="node13.html">
<LINK REL="up" HREF="tut.html">
<LINK REL="next" HREF="node15.html">
<meta name='aesop' content='information'>
</head>
<body>
<DIV CLASS="navigation">
<table align="center" width="100%" cellpadding="0" cellspacing="2">
<tr>
<td><A HREF="node13.html"><img src="../icons/previous.gif"
border="0" height="32"
alt="Previous Page" width="32"></A></td>
<td><A HREF="tut.html"><img src="../icons/up.gif"
border="0" height="32"
alt="Up One Level" width="32"></A></td>
<td><A HREF="node15.html"><img src="../icons/next.gif"
border="0" height="32"
alt="Next Page" width="32"></A></td>
<td align="center" width="100%">CherryPy Tutorial</td>
<td><A HREF="node2.html"><img src="../icons/contents.gif"
border="0" height="32"
alt="Contents" width="32"></A></td>
<td><img src="../icons/blank.gif"
border="0" height="32"
alt="" width="32"></td>
<td><img src="../icons/blank.gif"
border="0" height="32"
alt="" width="32"></td>
</tr></table>
<b class="navlabel">Previous:</b> <a class="sectref" HREF="node13.html">11. Handling HTML forms</A>
<b class="navlabel">Up:</b> <a class="sectref" HREF="tut.html">CherryPy Tutorial</A>
<b class="navlabel">Next:</b> <a class="sectref" HREF="node15.html">13. Using your own</A>
<br><hr>
</DIV>
<!--End of Navigation Panel-->
<!--Table of Child-Links-->
<A NAME="CHILD_LINKS"><STRONG>Subsections</STRONG></a>
<UL CLASS="ChildLinks">
<LI><A href="node14.html#SECTION0014100000000000000000">12.1 Changing the port</a>
<LI><A href="node14.html#SECTION0014200000000000000000">12.2 Serving static content</a>
<LI><A href="node14.html#SECTION0014300000000000000000">12.3 Changing the name fo the configuration file</a>
</ul>
<!--End of Table of Child-Links-->
<HR>
<H1><A NAME="SECTION0014000000000000000000">
12. Configuring CherryPy</A>
</H1>
Up to now, you've always run CherryPy's server on port 8000. Well, that's nice, but how do I
change that ? It's very easy: it's done through a configuration file.
<P>
<H1><A NAME="SECTION0014100000000000000000">
12.1 Changing the port</A>
</H1>
In the <span class="file">hello/</span> directory, where the <span class="file">Hello.cpy</span> and <span class="file">HelloServer.py</span> files sit, create a file
called <span class="file">HelloServer.cfg</span> with the following lines:
<div class="verbatim"><pre>
[server]
socketPort=80
</pre></div>
Restart the server... It's now serving on port 80.
<P>
Some other options are available in the <var>[server]</var> section of the config file. Check
out the "Deploying your website for production" chapter for more information about the different options.
<P>
<H1><A NAME="SECTION0014200000000000000000">
12.2 Serving static content</A>
</H1>
It you want to use CherryPy to serve static content, all you have to do is add a few other lines in the configuration file:
<div class="verbatim"><pre>
[staticContent]
static=/home/remi/static
data/images=/home/remi/images
</pre></div>
This means that when the browser requests the URL <a class="url" href="http://localhost/static/styleSheet.css">http://localhost/static/styleSheet.css</a>, the server will serve the
content of the file <span class="file">/home/remi/static/styleSheet.css</span>.
<P>
When the browser requests the URL <a class="url" href="http://localhost/data/images/girl.jpg">http://localhost/data/images/girl.jpg</a>, the server will serve the content of
the file <span class="file">/home/remi/images/girl.jpg</span>
<P>
Note that if you need to server static content at the root of your website (for
instance, <var>favicon.ico</var>), then you can specify the full name of the file
instead of the directory, like this:
<div class="verbatim"><pre>
[staticContent]
favicon.ico=/home/remi/images/favicon.ico
</pre></div>
<P>
<H1><A NAME="SECTION0014300000000000000000">
12.3 Changing the name fo the configuration file</A>
</H1>
If you want to use a different name for the configuration file, just use the <var>-C</var> option when you start the server.
For instance, if your configuration file is called <span class="file">/dir1/dir2/myConfigFile.cfg</span>, just start the server
by typing:
<div class="verbatim"><pre>
python HelloServer.py -C /dir1/dir2/myConfigFile.cfg
</pre></div>
<P>
<DIV CLASS="navigation">
<p><hr>
<table align="center" width="100%" cellpadding="0" cellspacing="2">
<tr>
<td><A HREF="node13.html"><img src="../icons/previous.gif"
border="0" height="32"
alt="Previous Page" width="32"></A></td>
<td><A HREF="tut.html"><img src="../icons/up.gif"
border="0" height="32"
alt="Up One Level" width="32"></A></td>
<td><A HREF="node15.html"><img src="../icons/next.gif"
border="0" height="32"
alt="Next Page" width="32"></A></td>
<td align="center" width="100%">CherryPy Tutorial</td>
<td><A HREF="node2.html"><img src="../icons/contents.gif"
border="0" height="32"
alt="Contents" width="32"></A></td>
<td><img src="../icons/blank.gif"
border="0" height="32"
alt="" width="32"></td>
<td><img src="../icons/blank.gif"
border="0" height="32"
alt="" width="32"></td>
</tr></table>
<b class="navlabel">Previous:</b> <a class="sectref" HREF="node13.html">11. Handling HTML forms</A>
<b class="navlabel">Up:</b> <a class="sectref" HREF="tut.html">CherryPy Tutorial</A>
<b class="navlabel">Next:</b> <a class="sectref" HREF="node15.html">13. Using your own</A>
<hr>
<span class="release-info">Release 0.10, documentation updated on 19 March 2004.</span>
</DIV>
<!--End of Navigation Panel-->
<ADDRESS>
See <i><a href="about.html">About this document...</a></i> for information on suggesting changes.
</ADDRESS>
</BODY>
</HTML>
|