Cherry and the relative path in the WSGI application

runs cherrypy with mod_wsgi on apache along with another php application. The cherry application is NOT mounted in the root directory, but rather looks like "localhost / apps / myapp" through WSGIScriptAlias ​​in the apache configuration file.

In testapp.py, I 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 root of the server, and not as to where it is mounted via WSGI in apache.

Is there a preferred way to make cherry applications work relative to the path they install in apache in WSGIScriptAlias?

Basically, I will run several cherry applications in several different ways and prefer that apache handle dispatching (i.e. cherry just starts the application and doesn't worry about the relative path). This way, I can avoid updating multiple python files / configuration files every time some of the relative paths on the server change.

Any suggestions?

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

 app = cherrypy.tree.mount(HelloWorld(), '', 'settings.config') return app(environ, start_response) 
+6
python cherrypy
source share
2 answers

I do this, although this will 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 that I need. I use nginx, not Apache, but I do not think it will make a difference. Although it becomes a bit verbose if you use long paths, but not much more in between.

cherrypy may support other dispatchers , which may be better suited to what you are trying to do, or perhaps you need to write your own.

+1
source share

how it should be

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

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

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

0
source share

All Articles