hsi*_*mah 4 python iis-6 cherrypy isapi-wsgi
我有一个使用Cherrypy框架的小型Python Web应用程序.我绝不是网络服务器的专家.
我在我们的Ubuntu服务器上使用mod_python让Cherrypy使用Apache.但是,这一次,我必须使用Windows 2003和IIS 6.0来托管我的网站.
该网站作为一个独立的服务器完美运行 - 我在使IIS运行时迷失了方向.我在过去的一天里用谷歌搜索并盲目地尝试任何一切,以便让它运行起来.
我已经安装了网站告诉我的所有各种工具(Python 2.6,CherrpyPy 3,ISAPI-WSGI,PyWin32),并且已经阅读了所有文档.这篇博客最有帮助:
http://whatschrisdoing.com/blog/2008/07/10/turbogears-isapi-wsgi-iis/
但我仍然迷失了运行我的网站所需要的东西.我找不到任何详尽的例子或者如何开始.我希望这里有人可以提供帮助!
干杯.
Jas*_*mbs 10
我在IIS网站后面运行CherryPy.有几个技巧可以让它发挥作用.
了解运行ISAPI应用程序的基本过程非常重要.我建议首先在ISAPI_WSGI下运行一个hello-world WSGI应用程序.这是一个钩子脚本的早期版本,我用它来验证我是否正在使用CherryPy来处理我的Web服务器.
#!python
"""
Things to remember:
easy_install munges permissions on zip eggs.
anything that's installed in a user folder (i.e. setup develop) will probably not work.
There may still exist an issue with static files.
"""
import sys
import os
import isapi_wsgi
# change this to '/myapp' to have the site installed to only a virtual
# directory of the site.
site_root = '/'
if hasattr(sys, "isapidllhandle"):
import win32traceutil
appdir = os.path.dirname(__file__)
egg_cache = os.path.join(appdir, 'egg-tmp')
if not os.path.exists(egg_cache):
os.makedirs(egg_cache)
os.environ['PYTHON_EGG_CACHE'] = egg_cache
os.chdir(appdir)
import cherrypy
import traceback
class Root(object):
@cherrypy.expose
def index(self):
return 'Hai Werld'
def setup_application():
print "starting cherrypy application server"
#app_root = os.path.dirname(__file__)
#sys.path.append(app_root)
app = cherrypy.tree.mount(Root(), site_root)
print "successfully set up the application"
return app
def __ExtensionFactory__():
"The entry point for when the ISAPIDLL is triggered"
try:
# import the wsgi app creator
app = setup_application()
return isapi_wsgi.ISAPISimpleHandler(app)
except:
import traceback
traceback.print_exc()
f = open(os.path.join(appdir, 'critical error.txt'), 'w')
traceback.print_exc(file=f)
f.close()
def install_virtual_dir():
import isapi.install
params = isapi.install.ISAPIParameters()
# Setup the virtual directories - this is a list of directories our
# extension uses - in this case only 1.
# Each extension has a "script map" - this is the mapping of ISAPI
# extensions.
sm = [
isapi.install.ScriptMapParams(Extension="*", Flags=0)
]
vd = isapi.install.VirtualDirParameters(
Server="CherryPy Web Server",
Name=site_root,
Description = "CherryPy Application",
ScriptMaps = sm,
ScriptMapUpdate = "end",
)
params.VirtualDirs = [vd]
isapi.install.HandleCommandLine(params)
if __name__=='__main__':
# If run from the command-line, install ourselves.
install_virtual_dir()
Run Code Online (Sandbox Code Playgroud)
这个脚本做了几件事.它(a)充当安装程序,将其自身安装到IIS [install_virtual_dir]中,(b)包含IIS加载DLL [__ExtensionFactory__]时的入口点,以及(c)它创建ISAPI处理程序使用的CherryPy WSGI实例[setup_application] ].
如果将其放在\ inetpub\cherrypy目录中并运行它,它将尝试将自身安装到名为"CherryPy Web Server"的IIS网站的根目录.
您也可以查看我的生产网站代码,该代码已将所有这些代码重构为不同的模块.