Deploying a Web.py Application with WSGI, Multiple Servers

I created the web.py application, and now that it is ready to be deployed, I want to run it not on the web.py web server. I want to be able to run it on different web servers, Apache or IIS, without having to change the application code. This is where the WSGI should go in if I understand it correctly.
However, I do not understand what should I do to make my application deployable on the WSGI server? Most examples assume that you are using Pylons / Django / other-framework, on which you simply run some kind of magic command that fixes everything for you.
From what I understand in the (rather brief) documentation of web.py, instead of running web.application(...).run() , I have to use web.application(...).wsgifunc() . What happened next?

+6
python web.py wsgi
source share
3 answers

What you need to do to host it with a specific WSGI hosting mechanism depends on the server.

In the case of Apache / mod_wsgi and Phusion Passenger, you just need to provide a WSGI script file that contains an object called an "application." For web.py 0.2, this is the result of calling web.wsgifunc () with the corresponding arguments. For web.py 0.3, you use the member function wsgifunc () of the object returned by web.application () instead. For more information, see the mod_wsgi documentation:

http://code.google.com/p/modwsgi/wiki/IntegrationWithWebPy

If instead you need to use FASTCGI, SCGI, or AJP adapters for a server such as Lighttpd, nginx, or Cherokee, then you need to use the “flup” package to provide a bridge between these language agnostic interfaces and WSGI. This includes calling the flup function with the same WSGI application object as something like mod_wsgi, or Phusion Passenger will use directly without the need for a bridge. For more details, see:

http://trac.saddi.com/flup/wiki/FlupServers

It is important to structure your web application so that it is in its own set of modules. To work with a specific server, create a separate script file necessary for the connection between what is required for this server and the code of your application. Your application code should always be outside the directory of the web server document, and only the script file, which acts as a bridge, will be located in the server document directory if necessary.

+6
source share

As of July 21, 2009, there is a much more comprehensive installation guide for the webpy installation website , which discusses flup , fastcgi , apache, and more. I have not tried it yet, but it seems more detailed.

0
source share

Here is an example of two hosted applications using the cherrypy-based wsgi server:

 #! / usr / bin / python
 from web import wsgiserver
 import web

 # webpy wsgi app
 urls = (
   '/test.*', 'index'
 )

 class index:
     def GET (self):
         web.header ("content-type", "text / html")
         return "Hello, world1!"

 application = web.application (urls, globals (), autoreload = False) .wsgifunc () 


 # generic wsgi app
 def my_blog_app (environ, start_response):
     status = '200 OK'
     response_headers = [('Content-type', 'text / plain')]
     start_response (status, response_headers)
     return ['Hello world!  - blog \ n ']


 "" "
 # single hosted app
 server = wsgiserver.CherryPyWSGIServer (
             ('0.0.0.0', 8070), application,
             server_name = 'www.cherrypy.example')

 "" "

 # multiple hosted apps with WSGIPathInfoDispatcher
 d = wsgiserver.WSGIPathInfoDispatcher ({'/ test': application, '/ blog': my_blog_app})
 server = wsgiserver.CherryPyWSGIServer (('0.0.0.0', 8070), d)            
 server.start ()
0
source share

All Articles