URI handler mapping incorrectly

Anonymous avatarAnonymous created an issue

I'm having an issue with CherryPy's URI handler. It seems to be mapping incorrectly. I'm using it with lighttpd. Here is lighttpd.conf (with commented blocks removed for brevity):

# lighttpd configuration file
#
# use it as a base for lighttpd 1.0.0 and above
#
# $Id: lighttpd.conf,v 1.7 2004/11/03 22:26:05 weigon Exp $

server.modules              = (
                               "mod_rewrite",
#                               "mod_redirect",
                                "mod_alias",
                                "mod_access",
#                               "mod_trigger_b4_dl",
#                               "mod_auth",
#                               "mod_status",
#                               "mod_setenv",
                                "mod_fastcgi",
#                               "mod_proxy",
#                               "mod_simple_vhost",
#                               "mod_evhost",
#                               "mod_userdir",
#                               "mod_cgi",
                                "mod_compress",
#                               "mod_ssi",
#                               "mod_usertrack",
#                               "mod_expire",
#                               "mod_secdownload",
#                               "mod_rrdtool",
                                "mod_accesslog" )

server.document-root        = "/usr/local/www/"

server.errorlog             = "/var/log/lighttpd/lighttpd.error.log"

index-file.names            = ( "index.php", "index.html",
                                "index.htm", "default.htm" )

server.event-handler = "freebsd-kqueue" # needed on OS X

mimetype.assign             = (
  ".pdf"          =>      "application/pdf",
  ".sig"          =>      "application/pgp-signature",
  ".spl"          =>      "application/futuresplash",
  ".class"        =>      "application/octet-stream",
  ".ps"           =>      "application/postscript",
  ".torrent"      =>      "application/x-bittorrent",
  ".dvi"          =>      "application/x-dvi",
  ".gz"           =>      "application/x-gzip",
  ".pac"          =>      "application/x-ns-proxy-autoconfig",
  ".swf"          =>      "application/x-shockwave-flash",
  ".tar.gz"       =>      "application/x-tgz",
  ".tgz"          =>      "application/x-tgz",
  ".tar"          =>      "application/x-tar",
  ".zip"          =>      "application/zip",
  ".mp3"          =>      "audio/mpeg",
  ".m3u"          =>      "audio/x-mpegurl",
  ".wma"          =>      "audio/x-ms-wma",
  ".wax"          =>      "audio/x-ms-wax",
  ".ogg"          =>      "application/ogg",
  ".wav"          =>      "audio/x-wav",
  ".gif"          =>      "image/gif",
  ".jar"          =>      "application/x-java-archive",
  ".jpg"          =>      "image/jpeg",
  ".jpeg"         =>      "image/jpeg",
  ".png"          =>      "image/png",
  ".xbm"          =>      "image/x-xbitmap",
  ".xpm"          =>      "image/x-xpixmap",
  ".xwd"          =>      "image/x-xwindowdump",
  ".css"          =>      "text/css",
  ".html"         =>      "text/html",
  ".htm"          =>      "text/html",
  ".js"           =>      "text/javascript",
  ".asc"          =>      "text/plain",
  ".c"            =>      "text/plain",
  ".cpp"          =>      "text/plain",
  ".log"          =>      "text/plain",
  ".conf"         =>      "text/plain",
  ".text"         =>      "text/plain",
  ".txt"          =>      "text/plain",
  ".dtd"          =>      "text/xml",
  ".xml"          =>      "text/xml",
  ".mpeg"         =>      "video/mpeg",
  ".mpg"          =>      "video/mpeg",
  ".mov"          =>      "video/quicktime",
  ".qt"           =>      "video/quicktime",
  ".avi"          =>      "video/x-msvideo",
  ".asf"          =>      "video/x-ms-asf",
  ".asx"          =>      "video/x-ms-asf",
  ".wmv"          =>      "video/x-ms-wmv",
  ".bz2"          =>      "application/x-bzip",
  ".tbz"          =>      "application/x-bzip-compressed-tar",
  ".tar.bz2"      =>      "application/x-bzip-compressed-tar",
  # default mime type
  ""              =>      "application/octet-stream",
 )

#mimetype.use-xattr        = "enable"

# server.tag                 = "lighttpd"

accesslog.filename          = "/var/log/lighttpd/lighttpd.access.log"

url.access-deny             = ( "~", ".inc" )

$HTTP["url"] =~ "\.pdf$" {
  server.range-requests = "disable"
}

static-file.exclude-extensions = ( ".php", ".pl", ".fcgi" )

#server.port                = 81

#server.bind                = "127.0.0.1"

#server.error-handler-404   = "/error-handler.html"
#server.error-handler-404   = "/error-handler.php"

server.pid-file            = "/var/run/lighttpd.pid"

#simple-vhost.server-root   = "/srv/www/vhosts/"
#simple-vhost.default-host  = "www.example.org"
#simple-vhost.document-root = "/htdocs/"

#server.errorfile-prefix    = "/usr/share/lighttpd/errors/status-"
#server.errorfile-prefix    = "/srv/www/errors/status-"

#dir-listing.activate       = "enable"
#dir-listing.encoding        = "utf-8"

#debug.log-request-header   = "enable"
#debug.log-response-header  = "enable"
#debug.log-request-handling = "enable"
#debug.log-file-not-found   = "enable"

#server.chroot              = "/"

#compress.cache-dir         = "/var/cache/lighttpd/compress/"
#compress.filetype          = ("text/plain", "text/html")

#proxy.server               = ( ".php" =>
#                               ( "localhost" =>
#                                 (
#                                   "host" => "192.168.0.101",
#                                   "port" => 80
#                                 )
#                               )
#                             )

#fastcgi.server             = ( ".php" =>
#                               ( "localhost" =>
#                                 (
#                                   "socket" => "/var/run/lighttpd/php-fastcgi.socket",
#                                   "bin-path" => "/usr/local/bin/php-cgi-cgi"
#                                 )
#                               )
#                            )

#cgi.assign                 = ( ".pl"  => "/usr/bin/perl",
#                               ".cgi" => "/usr/bin/perl" )
#

#ssl.engine                 = "enable"
#ssl.pemfile                = "/etc/ssl/private/lighttpd.pem"

#status.status-url          = "/server-status"
#status.config-url          = "/server-config"

## read authentication.txt for more info
#auth.backend               = "plain"
#auth.backend.plain.userfile = "lighttpd.user"
#auth.backend.plain.groupfile = "lighttpd.group"

#auth.backend.ldap.hostname = "localhost"
#auth.backend.ldap.base-dn  = "dc=my-domain,dc=com"
#auth.backend.ldap.filter   = "(uid=$)"

#auth.require               = ( "/server-status" =>
#                               (
#                                 "method"  => "digest",
#                                 "realm"   => "download archiv",
#                                 "require" => "user=jan"
#                               ),
#                               "/server-config" =>
#                               (
#                                 "method"  => "digest",
#                                 "realm"   => "download archiv",
#                                 "require" => "valid-user"
#                               )
#                             )

#url.rewrite                = ( "^/$"             => "/server-status" )

#url.rewrite-once = ("^(/.*)$" => "/$1/",) 
#url.redirect               = ( "^/wishlist/(.+)" => "http://www.123.org/$1" )

#$HTTP["host"] =~ "^www\.(.*)" {
#  url.redirect            = ( "^/(.*)" => "http://%1/$1" )
#}

#
# define a pattern for the host url finding
# %% => % sign
# %0 => domain name + tld
# %1 => tld
# %2 => domain name without tld
# %3 => subdomain 1 name
# %4 => subdomain 2 name
#
#evhost.path-pattern        = "/srv/www/vhosts/%3/htdocs/"

#expire.url                 = ( "/buggy/" => "access 2 hours", "/asdhas/" => "access plus 1 seconds 2 minutes")

#ssi.extension              = ( ".shtml" )

#rrdtool.binary             = "/usr/bin/rrdtool"
#rrdtool.db-name            = "/var/lib/lighttpd/lighttpd.rrd"

#setenv.add-request-header  = ( "TRAV_ENV" => "mysql://user@host/db" )
#setenv.add-response-header = ( "X-Secret-Message" => "42" )

# trigger-before-download.gdbm-filename = "/var/lib/lighttpd/trigger.db"
# trigger-before-download.memcache-hosts = ( "127.0.0.1:11211" )
# trigger-before-download.trigger-url = "^/trigger/"
# trigger-before-download.download-url = "^/download/"
# trigger-before-download.deny-url = "http://127.0.0.1/index.html"
# trigger-before-download.trigger-timeout = 10

#bar = 1
#var.mystring = "foo"

#bar += 1
#server.name = "www." + mystring + var.bar + ".com"
#index-file.names = (foo + ".php") + index-file.names
#index-file.names += (foo + ".php")

#include /etc/lighttpd/lighttpd-inc.conf
#include "lighttpd-inc.conf"

#include_shell "echo var.a=1"
#var.a=1

# Enable IPV6 and IPV4 together
server.use-ipv6 = "enable"
$SERVER["socket"] == "0.0.0.0:80" { }

$HTTP["host"] =~ "" {
  fastcgi.server = (
    "/" => (
      "cherrypy" => (
        "host"          => "127.0.0.1",
        "port"          => 4001,
        "check-local"   => "disable",
        "disable-time"  => 1,
        "min-procs"     => 1,
        "max-procs"     => 1,
      )
    )
  )
}

Here's the code for my application (Pardon the length):

import cherrypy
from cherrypy import expose

class HelloWorld:
    """ Sample request handler class. """
    @expose
    def index(self):
        return "CherryPy Works! See, FreeBSD IS better :P<br/><a href='blargh'>Click here!</a><br /><img src = '/images/win.jpg'><br /><img src = '/images/win2.jpg'>"

    @expose
    def blargh(self):
        return "See, even this works properly!"

conf = {
        '/images/win.jpg':{
                          'tools.staticfile.on' : True,
                          'tools.staticfile.filename' : '/usr/local/www/images/win.jpg',
                          },

        #SEE http://www.cherrypy.org/wiki/StaticContent FOR INFO THAT DOESN'T HELP
        '/':{
            'tools.staticdir.root' : '/usr/local/www' 
            },
	 '/images':{
                  'tools.staticdir.on' : True,
                  'tools.staticdir.dir' : 'images',
                  },
       }


cherrypy.tree.mount(HelloWorld(), '/', config=conf)
cherrypy.config.update({'server.socket_host':"127.0.0.1",
                        'server.socket_port':4001,})

# CherryPy autoreload must be disabled for the flup server to work
cherrypy.config.update({'engine.autoreload_on':False})

However, requests to .../blargh get mapped to /blargh/blargh, which naturally will 404. Here is the error from the terminal output:

99.56.120.179 - - [03/Mar/2010:20:31:58] "GET /blargh/blargh HTTP/1.1" 404 1281 "http://www.studentcommon.com/" "Mozilla/5.0 (Windows; U; Windows NT 6.0; en-US; rv:1.9.1.8) Gecko/20100202 Firefox/3.5.8"

Requests to /blargh should simply be going to /blargh/, but I cannot figure out what's going on. If you have any information, or you need me to provide more, lemme know. Thanks!

Brandon

Reported by absensperegrinus@gmail.com

Comments (3)

  1. Anonymous

    ...Have you tried without lighttpd? Your example looks like it works fine for the CherryPy part.

  2. Log in to comment
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.