Subsections
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.
In the hello/ directory, where the Hello.cpy and HelloServer.py files sit, create a file
called HelloServer.cfg with the following lines:
Restart the server... It's now serving on port 80.
Some other options are available in the [server] section of the config file. Check
out the "Deploying your website for production" chapter for more information about the different options.
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:
[staticContent]
static=/home/remi/static
data/images=/home/remi/images
This means that when the browser requests the URL http://localhost/static/styleSheet.css, the server will serve the
content of the file /home/remi/static/styleSheet.css.
When the browser requests the URL http://localhost/data/images/girl.jpg, the server will serve the content of
the file /home/remi/images/girl.jpg
Note that if you need to server static content at the root of your website (for
instance, favicon.ico), then you can specify the full name of the file
instead of the directory, like this:
[staticContent]
favicon.ico=/home/remi/images/favicon.ico
If you want to use a different name for the configuration file, just use the -C option when you start the server.
For instance, if your configuration file is called /dir1/dir2/myConfigFile.cfg, just start the server
by typing:
python HelloServer.py -C /dir1/dir2/myConfigFile.cfg
See About this document... for information on suggesting changes.