Download Install Tutorial Docs FAQ Tools WikiLicense Team IRC Planet Involvement Shop Book

Ticket #607 (defect)

Opened 2 years ago

Last modified 2 years ago

virtual_host and staticdir tools don't play well together

Status: closed (worksforme)

Reported by: ricardo Assigned to: fumanchu
Priority: normal Milestone: 3.0
Component: CherryPy code Keywords: virtual_host staticdir
Cc:

I'm trying to use CherryPy as a full replacement for Apache. Besides my web application, I have several different static directories that I want to serve up on the same server, each under its own domain name. The virtual_host tool is the obvious solution. Unfortunately, a server that invokes the virtual_host tool can only serve up the index file of a static directory, and will do that much only if the URL contains nothing more than the domain name. The moment the URL also specifies an index file for a virtual host, or in fact ANY file (whether in the root of the static directory or below it), a 404 error is generated.

Change History

11/27/06 17:02:01: Modified by fumanchu

  • owner changed from rdelon to fumanchu.
  • status changed from new to assigned.

A simple test case (see [1453]) shows there's no problem using vhost and static together. Perhaps you could post the offending code?

11/27/06 20:24:37: Modified by ricardo

I'm running the following code (under the latest 3.0 beta release):

import cherrypy

class Root:

pass

conf = {'/':{'tools.virtual_host.on':True,

'tools.virtual_host.mpp.net':'/mpp' },

'/mpp':{'tools.staticdir.on': True,

'tools.staticdir.index':'index.htm', 'tools.staticdir.dir': '/home/user/sites/mpp' }

}

cherrypy.quickstart(Root(), '/', config=conf)

I can browse http://mpp.net/, but not http://mpp.net/index.htm (or any other files in the same directory or its subdirectories). It's not clear to me whether the virtual_host entries should be placed under '/' or 'global'; but in any event the outcome was the same in both cases.

11/28/06 15:46:18: Modified by fumanchu

  • status changed from assigned to closed.
  • resolution set to worksforme.

Hmm. Rather than trying to get the beta tested and then working, I'm just going to say, "here's how to do it with 3.0RC1", in which virtual host functionality has rightly moved from a Tool to a dispatcher:

import cherrypy
from cherrypy import _cpdispatch

class Root:
    pass

conf = {'/': {'request.dispatch': _cpdispatch.VirtualHost(**{'mpp.net': '/mpp'})},
        '/mpp': {'tools.staticdir.on': True,
                 'tools.staticdir.index': 'index.html',
                 'tools.staticdir.dir': '/home/user/sites/mpp',
                 },
        }
cherrypy.quickstart(Root(), '/', config=conf)

..which works just fine. One thing to note is that the virtual host domain mapping does not do subdomain matching; that is, if the Host header says "www.mpp.net", that's not going to match the "mpp.net" entry you've specified; you need to have a separate entry in the domain map for "www.mpp.net".

Hosted by WebFaction

Log in as guest/cpguest to create tickets