Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Deploying a Web.py application with WSGI, several servers

I've created a web.py application, and now that it is ready to be deployed, I want to run in not on web.py's built-in webserver. I want to be able to run it on different webservers, Apache or IIS, without having to change my application code. This is where WSGI is supposed to come in, if I understand it correctly.
However, I don't understand what exacly I have to do to make my application deployable on a WSGI server? Most examples assume you are using Pylons/Django/other-framework, on which you simply run some magic command which fixes everything for you.
From what I understand of the (quite brief) web.py documentation, instead of running web.application(...).run(), I should use web.application(...).wsgifunc(). And then what?

like image 871
carlpett Avatar asked Jul 03 '09 09:07

carlpett


People also ask

Why is WSGI server needed?

WSGI servers are designed to handle many requests concurrently. Frameworks are not made to process thousands of requests and determine how to best route them from the server. WSGI speeds up Python web application development because you only need to know basic things about WSGI.

Is WSGI an application server?

Specification overview The WSGI has two sides: the server/gateway side. This is often running full web server software such as Apache or Nginx, or is a lightweight application server that can communicate with a webserver, such as flup. the application/framework side.

What Python framework can also be used as a production WSGI server for other frameworks?

CherryPy is a pure Python web server that also functions as a WSGI server.


1 Answers

Exactly what you need to do to host it with a specific WSGI hosting mechanism varies with the server.

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

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

If instead you are having to use FASTCGI, SCGI or AJP adapters for a server such as Lighttpd, nginx or Cherokee, then you need to use 'flup' package to provide a bridge between those language agnostic interfaces and WSGI. This involves calling a flup function with the same WSGI application object above that something like mod_wsgi or Phusion Passenger would use directly without the need for a bridge. For details of this see:

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

Important thing is to structure your web application so that it is in its own self contained set of modules. To work with a particular server, then create a separate script file as necessary to bridge between what that server requires and your application code. Your application code should always be outside of the web server document directory and only the script file that acts as bridge would be in server document directory if appropriate.

like image 54
Graham Dumpleton Avatar answered Oct 13 '22 01:10

Graham Dumpleton