使用 WSGI 和多个服务器部署 Web.py 应用程序
我已经创建了一个 web.py 应用程序,现在它已准备好部署,我想在 web.py 的内置网络服务器上运行。 我希望能够在不同的 Web 服务器(Apache 或 IIS)上运行它,而无需更改我的应用程序代码。 如果我理解正确的话,这就是 WSGI 应该发挥作用的地方。
但是,我不明白我究竟需要做什么才能使我的应用程序可部署在 WSGI 服务器上? 大多数示例假设您正在使用 Pylons/Django/other-framework,您只需运行一些神奇的命令即可为您解决所有问题。
根据我对(非常简短的)web.py 文档的理解,我应该使用 web.application(.. .).wsgifunc()
。 然后什么?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
使用特定 WSGI 托管机制托管它所需执行的操作因服务器而异。
对于 Apache/mod_wsgi 和 Phusion Passenger 的情况,您只需要提供一个 WSGI 脚本文件,其中包含一个名为“application”的对象。 对于 web.py 0.2,这是使用适当参数调用 web.wsgifunc() 的结果。 对于 web.py 0.3,您可以使用 web.application() 返回的对象的 wsgifunc() 成员函数。 有关这些的详细信息,请参阅 mod_wsgi 文档:
http://code.google.com/p/modwsgi /wiki/IntegrationWithWebPy
如果您必须为 Lighttpd、nginx 或 Cherokee 等服务器使用 FASTCGI、SCGI 或 AJP 适配器,那么您需要使用“flup”包在这些与语言无关的接口之间提供桥梁和 WSGI。 这涉及到使用上面相同的 WSGI 应用程序对象调用 flup 函数,mod_wsgi 或 Phusion Passenger 之类的东西可以直接使用,而不需要桥接。 有关详细信息,请参阅:
http://trac.saddi.com/flup/wiki/FlupServers
重要的是构建您的 Web 应用程序,使其位于自己包含的模块集中。 要使用特定服务器,请根据需要创建一个单独的脚本文件,以在该服务器所需的内容和您的应用程序代码之间建立桥梁。 您的应用程序代码应始终位于 Web 服务器文档目录之外,并且只有充当桥接器的脚本文件才会位于服务器文档目录(如果适用)中。
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.
截至 2009 年 7 月 21 日,webpy 安装站点上有一个更完整的安装指南,其中讨论了 flup、fastcgi、apache 等等。 我还没有尝试过,但看起来它更详细。
As of July 21 2009, there is a much fuller installation guide at the webpy install site, that discusses flup, fastcgi, apache and more. I haven't yet tried it, but it seems like it's much more detailed.
以下是使用cherrypy wsgi服务器的两个托管应用程序的示例:
Here is an example of two hosted apps using cherrypy wsgi server: