cherrypy and relative path in WSGI app
Asked Answered
H

2

6

running cherrypy with mod_wsgi on apache along with another php app. The cherrypy app is NOT mounted on root, but rather on something like 'localhost/apps/myapp' via WSGIScriptAlias in the apache config file.

In testapp.py, I have tried the following, and when I try to access localhost/apps/myapp in a browser:

app = cherrypy.tree.mount(MyApp(), '', 'settings.config') #FAILS WITH 404

and

app = cherrypy.tree.mount(MyApp(), '/apps/myapp', 'settings.config') # WORKS

The first case fails because cherrypy expects to be at the server root, instead of relative to where it is mounted via WSGI in apache.

Is there a preferred way to make cherrypy apps work relative to the path they are mounted in apache under WSGIScriptAlias?

Basically, I'll be running several cherrypy apps under several different paths, and would prefer if apache handled the dispatching (i.e. cherrypy just runs the app and doesn't worry about the relative path). This way i can avoid updating several different python files/config files everytime some of the relative paths on the server change.

Any suggestions?

btw, the cherrypy app is currently passed to the wsgi application as follows:

app = cherrypy.tree.mount(HelloWorld(), '', 'settings.config')
return app(environ, start_response)
Harp answered 9/11, 2010 at 2:16 Comment(0)
E
1

I am doing this, although this would require cherrypy to know the relative path:

class Dir: pass
root = Dir()
root.apps = Dir()
root.apps.myapp = MyApp()
cherrypy.tree.mount(root)

This allows me to structure the application in any way I need. I'm using nginx and not Apache, but I don't think it'll make any difference. Although it gets a bit wordy if you're using long paths with not much else in between.

cherrypy can support other dispatchers which might be better suited to what you're trying to do, or perhaps you need to write a custom one.

Euphrosyne answered 9/11, 2010 at 11:50 Comment(0)
A
0

how should this

app = cherrypy.tree.mount(MyApp(), '', 'settings.config')

resolve http://localhost/apps/myapp ? have u tried http://localhost/ or http://localhost/MyApp.

it is also important where u have defined your WSGIScriptAlias in Apache. vhost, location?

Alligator answered 11/11, 2010 at 1:36 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.