Search code examples
cherrypy

How to get CherryPy's cherryd serving static files


I just want to start up a server, point it at a directory and have it serve static files. I thought cherryd would be good/easy for that.

I've read the cherryd usage and a good portion of the online docs, as well as posts here about static files and CherryPy, but I've yet to find information about a bare configuration file for cherryd. I've been able to piece together the following:

[global]
server.socket_host: "127.0.0.1"
server.socket_port: 8000
log.error_file = '/Users/chb/code/app/test/log/cherrypy.error.log'

[/]
tools.staticdir.on: True
tools.staticdir.root: '/Users/chb/code/app'
tools.staticdir.dir: '.'

I also tried this alternate configuration:

[global]
server.socket_host: "127.0.0.1"
server.socket_port: 8000
log.error_file = '/Users/chb/code/app/test/log/cherrypy.error.log'

[/]
tools.staticdir.root: '/Users/chb/code/app'

[/index.html]
tools.staticfile.on: True
tools.staticfile.filename: '/Users/chb/code/app/index.html'

The latter adheres more to the docs (see below).

Visiting 127.0.0.1:8000 gets me a 404. When I tail the error log after running cherryd -c /path/to/cherryd.cfg, nothing comes up apart from the standard startup info.

This question relates to CherryPy 3.2.2 and Python 2.7.3

Relevant pages in the docs:


Solution

  • My error was in thinking that cherryd is a simple HTTP daemon that can run absent a user-created Python script.

    What I wanted was something like lighttpd. I came across this document and wondered if there was something simliar implemented in Python.

    Fortunately, after some more searching I came across the one-liner mentioned in the comments to the original post.