CherryPy3和IIS 6.0
-
16-09-2019 - |
题
我有使用CherryPy的框架小Python网络应用程序。我绝不是在Web服务器方面的专家。
我的CherryPy与Apache使用我们的Ubuntu的服务器上mod_python的工作。然而这一次,我一定要使用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 /
但我还是输了,什么我需要运行我的网站。我找不到任何彻底的例子或怎么对的,甚至下手。我希望这里有人能帮助!
干杯。
解决方案 2
OK,我懂了工作。感谢Jason和他的所有帮助。我需要调用
cherrypy.config.update({
'tools.sessions.on': True
})
return cherrypy.tree.mount(Root(), '/', config=path_to_config)
我下[/],但由于某种原因,它不喜欢的配置文件了这一点。现在,我可以让我的web应用程序启动和运行 - 然后我想我会尝试找出为什么它需要一个配置更新和不喜欢的配置文件,我有...
其他提示
我运行CherryPy的背后我的IIS网站。有几个技巧,以得到它的工作。
- 在当前的IIS工作进程标识运行,你不会有相同的权限,你当您从您的用户进程的网站做的。事情会打破。特别是,任何想要写文件系统可能没有一些调整工作。
- 如果您正在使用setuptools的,你可能要与-Z选项来安装你的组件(解压所有的鸡蛋)。
- 使用win32traceutil追查问题。可以肯定的是,在你的钩子脚本您导入win32traceutil。然后,当您试图访问的网站,如果有什么差错,确保它被打印到标准输出,它会得到记录到跟踪工具。使用“蟒-m win32traceutil”看到从跟踪输出。 醇>
要了解基本的过程中得到一个ISAPI应用程序的运行是非常重要的。我建议先取下ISAPI_WSGI运行一个hello世界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()
该脚本做几件事情。它(a)中作为安装程序,安装本身到IIS [install_virtual_dir],(b)中包含入口点时IIS加载DLL [__ExtensionFactory__],和(c)它创建由ISAPI处理器消耗的CherryPy的WSGI实例[setup_application ]
如果你把这个在您的\的Inetpub \ CherryPy的目录并运行它,它会尝试将自己安装到名为“CherryPy的Web服务器”您的IIS Web站点的根目录。
也欢迎您来看看我的制作的网站代码,这已重构到所有这些不同的模块。