[转载]windows2003上IIS+PyISAPIe1.1..0部署成功

PyISAPIe是一个IIS的ISAPI扩展,可以使IIS运行python脚本做的网站程序。

pyisapie的下载,就不介绍了。google解决。

安装,先解压到C:\pyisapie\,然后把Http目录复制到site-packages目录下即可。

右键单击c:\pyisapie\pyisapie.dll,选属性,然后在安全选项卡中,加入Network service和IIS_USERMACHINENAME(IIS用户访问账号,一定要加,不然,会要求你登录认证)

IIS中的配置,新建一个网站,主目录中的路径指向你喜欢的任意目录,然后在主目录的选项卡,点配置按钮,在弹出的框子中,在通配符的那个框框旁边,点添加,选中c:\pyisapie\pyisapie.dll,然后勾掉“确认文件是否存在”,不要选中这个。

新建web服务扩展,在扩展名(实际是扩展服务的名称,不是我们所知道的文件扩展名的意思,IIS中文翻译的问题),随意填写,然后在文件的框框旁边点击插入按钮,选择c:\pyisapie\pyisapie.dll文件就行了。

新建一个应用程序池,名字随意,比如取名为django test,建好后,右键选属性,然后把它设置为60分钟回收和1次请求后回收(目的是让它每次http请求后就重新加载代码),具体多少按照自己的喜好来。

将上面提到的Http目录中的Isapi.py文件修改为一下内容:

view plaincopy to clipboardprint?
# $URL: https://pyisapie.svn.sourceforge.net/svnroot/pyisapie/Tags/1.1.0-rc4/PyISAPIe/Python/Http/Isapi.py $  
# $Rev: 165 $ $Date: 2009-06-15 14:19:18 -0700 (Mon, 15 Jun 2009) $  
# (C)2008 Phillip Sitbon <phillip@sitbon.net>  
#  
"""Global ISAPI request handler. 
 
All requests go here - after the first successful 
import of this module & Request() function, it 
will not be reloaded for the life of the interpreter. 
 
This default simply attempts to load the file targeted 
by the URL and call its Request() function. Although 
SCRIPT_TRANSLATED is not available in IIS 5.x, it is 
emulated for completeness. 
 
I don't really recommend this method - it's not as 
package/module oriented as the Regex and Advanced 
examples, which can handle arbitrary URLs and pass 
them to preloaded handlers. 
 
ALSO: imp.load_source is NOT case-sensitive and doesn't 
follow the typical import case rules. You might like this 
but it's really not great behavior. 
 
See example Isapi.py files in ../Examples, including 
one that makes this version backwards compatible with 
v1.0.0 (in the Compat folder). 
""" 
from django.core.handlers.wsgi import WSGIHandler as DjangoHandler  
from Http.WSGI import RunWSGI  
from Http import Env  
import os  
import sys  
##############the 2 lines under is not nessery##############  
#sys.path.append('C:\\Python25\\Lib\\site-packages')  
#sys.path.append('C:\\Python25\\Lib\\site-packages\\django')  
############################################################  
 
#sys.path.append('F:\\Website\\Projects\\ysdy\\trunk\\')  
#sys.path.append('F:\\Website\\Projects\\ysdy\\trunk\\ddtcms')  
sys.path.append('E:\\')#fat32  
sys.path.append('E:\\ddtcms')#fat32  
 
#sys.path.append('F:\\')  
#sys.path.append('F:\\ddtcms')  
 
#sys.path.append('E:\\')  
#sys.path.append('E:\\mysite')  
 
 
os.environ["DJANGO_SETTINGS_MODULE"] = "ddtcms.settings" 
# os.environ["DJANGO_SETTINGS_MODULE"] = "mysite.settings"  
# This is how the WSGI module determines what part of the path  
# SCRIPT_NAME should consist of. If you configure PyISAPIe as  
# a wildcard map on the root of your site, you can leave this  
# value as-is.  
#   
Base = "/" 
 
# This is an example of what paths might need to be handled by  
# other parts of IIS that still come here first. This value's  
# default of "/media" assumes that you've mapped a virtual  
# directory to Django's admin media folder and so expect the  
# files to be served by the static file handler.  
#  
Exclude = ["/media"]  
 
 
 
# The main request handler.  
# This object can be re-created for every request if desired.  
#  
Handler = DjangoHandler()  
 
def Request():  
  PathInfo = Env.PATH_INFO  
    
  # There is no way to test if this ISAPI extension is configured  
  # as a wildcard handler, so this script will fail if it is not.  
  # If you'd rather have it as a script map, remove the checks below.  
  #  
  # You can also remove it if you set up this instance as a handler  
  # for a virtual directory and know that Base will always start  
  # with it. For example, if "/django_site_1" is the virtual directory  
  # you're running in, and Base is set to the same value, no need  
  # to ever pass control away from this handler.  
    
  # Pass through to the next handler if it's not  
  # part of our Django app.  
  #  
  if not PathInfo.startswith(Base):  
    return True 
 
  # Check for anything we know shouldn't be handled by Django and  
  # pass it back to IIS, which in most cases sends it to the static  
  # file handler.  
  #  
  for Excl in Exclude:  
    if PathInfo.startswith(Excl):  
      return True 
 
  return RunWSGI(Handler, Base=Base) 
# $URL: https://pyisapie.svn.sourceforge.net/svnroot/pyisapie/Tags/1.1.0-rc4/PyISAPIe/Python/Http/Isapi.py $
# $Rev: 165 $ $Date: 2009-06-15 14:19:18 -0700 (Mon, 15 Jun 2009) $
# (C)2008 Phillip Sitbon <phillip@sitbon.net>
#
"""Global ISAPI request handler.

All requests go here - after the first successful
import of this module & Request() function, it
will not be reloaded for the life of the interpreter.

This default simply attempts to load the file targeted
by the URL and call its Request() function. Although
SCRIPT_TRANSLATED is not available in IIS 5.x, it is
emulated for completeness.

I don't really recommend this method - it's not as
package/module oriented as the Regex and Advanced
examples, which can handle arbitrary URLs and pass
them to preloaded handlers.

ALSO: imp.load_source is NOT case-sensitive and doesn't
follow the typical import case rules. You might like this
but it's really not great behavior.

See example Isapi.py files in ../Examples, including
one that makes this version backwards compatible with
v1.0.0 (in the Compat folder).
"""
from django.core.handlers.wsgi import WSGIHandler as DjangoHandler
from Http.WSGI import RunWSGI
from Http import Env
import os
import sys
##############the 2 lines under is not nessery##############
#sys.path.append('C:\\Python25\\Lib\\site-packages')
#sys.path.append('C:\\Python25\\Lib\\site-packages\\django')
############################################################

#sys.path.append('F:\\Website\\Projects\\ysdy\\trunk\\')
#sys.path.append('F:\\Website\\Projects\\ysdy\\trunk\\ddtcms')
sys.path.append('E:\\')#fat32
sys.path.append('E:\\ddtcms')#fat32

#sys.path.append('F:\\')
#sys.path.append('F:\\ddtcms')

#sys.path.append('E:\\')
#sys.path.append('E:\\mysite')


os.environ["DJANGO_SETTINGS_MODULE"] = "ddtcms.settings"
# os.environ["DJANGO_SETTINGS_MODULE"] = "mysite.settings"
# This is how the WSGI module determines what part of the path
# SCRIPT_NAME should consist of. If you configure PyISAPIe as
# a wildcard map on the root of your site, you can leave this
# value as-is.
#
Base = "/"

# This is an example of what paths might need to be handled by
# other parts of IIS that still come here first. This value's
# default of "/media" assumes that you've mapped a virtual
# directory to Django's admin media folder and so expect the
# files to be served by the static file handler.
#
Exclude = ["/media"]

 

# The main request handler.
# This object can be re-created for every request if desired.
#
Handler = DjangoHandler()

def Request():
  PathInfo = Env.PATH_INFO
 
  # There is no way to test if this ISAPI extension is configured
  # as a wildcard handler, so this script will fail if it is not.
  # If you'd rather have it as a script map, remove the checks below.
  #
  # You can also remove it if you set up this instance as a handler
  # for a virtual directory and know that Base will always start
  # with it. For example, if "/django_site_1" is the virtual directory
  # you're running in, and Base is set to the same value, no need
  # to ever pass control away from this handler.
 
  # Pass through to the next handler if it's not
  # part of our Django app.
  #
  if not PathInfo.startswith(Base):
    return True

  # Check for anything we know shouldn't be handled by Django and
  # pass it back to IIS, which in most cases sends it to the static
  # file handler.
  #
  for Excl in Exclude:
    if PathInfo.startswith(Excl):
      return True

  return RunWSGI(Handler, Base=Base)

这个其实就是examples目录下的django文件夹中的那个isapi.py 文件的修改。

完成了之后,在你新建的网站上的主目录选项卡,选中应用程序池为djangotest。

然后就可以在django test 的应用程序池上,右键选回收。

然后在ie中浏览你的网站地址即可。

E:\ddtcms 是我的项目根目录,加入E:到sys.path是因为ddtcms在E:目录下,不加E:\话,ddtcms.settings

就找不到。

现在的问题是,你的django项目所在的硬盘分区必须是fat32的,ntfs的不行,我不知道为什么,因为我把network service和IIS_USer都加到了项目路径的,采用了完全控制的权限,都不行,甚至连everyone都是完全控制的。还是不行,看来是人品的问题。

下面是出错的信息:

Internal Server Error
An error occurred processing this request.

--------------------------------------------------------------------------------

Request handler failed

Traceback (most recent call last):
File "C:\Python25\lib\site-packages\Http\Isapi.py", line 102, in Request
return RunWSGI(Handler, Base=Base)
File "C:\Python25\lib\site-packages\Http\WSGI.py", line 155, in RunWSGI
Result = Application(Environ, StartResponse)
File "C:\Python25\lib\site-packages\django\core\handlers\wsgi.py", line 230, in __call__
self.load_middleware()
File "C:\Python25\lib\site-packages\django\core\handlers\base.py", line 33, in load_middleware
for middleware_path in settings.MIDDLEWARE_CLASSES:
File "C:\Python25\lib\site-packages\django\utils\functional.py", line 269, in __getattr__
self._setup()
File "C:\Python25\lib\site-packages\django\conf\__init__.py", line 40, in _setup
self._wrapped = Settings(settings_module)
File "C:\Python25\lib\site-packages\django\conf\__init__.py", line 75, in __init__
raise ImportError, "Could not import settings '%s' (Is it on sys.path? Does it have syntax errors?): %s" % (self.SETTINGS_MODULE, e)
ImportError: Could not import settings 'ddtcms.settings' (Is it on sys.path? Does it have syntax errors?): No module named ddtcms.settings

Additional Information

--------------------------------------------------------------------------------


-- Module Search Path --

C:\PyISAPIe-1.1.0-rc4-Py2.5
C:\WINDOWS\system32\python25.zip
C:\Python25\Lib
C:\Python25\DLLs
C:\Python25\Lib\lib-tk
c:\windows\system32\inetsrv
C:\Python25
C:\Python25\lib\site-packages
C:\Python25\lib\site-packages\PIL
C:\Python25\lib\site-packages\win32
C:\Python25\lib\site-packages\win32\lib
C:\Python25\lib\site-packages\Pythonwin
F:\
F:\ddtcms


-- Other Path Info --

Current Directory = 'C:\PyISAPIe-1.1.0-rc4-Py2.5'
Python Home = '<Auto>'
sys.executable = 'C:\PyISAPIe-1.1.0-rc4-Py2.5\PyISAPIe.dll'
sys.exec_prefix = 'C:\Python25'
sys.prefix = 'C:\Python25'

还有一个就是你必须装好vc9.0 CRT 运行库,google找到并安装吧,因为c:\pyisapie\pyisapie.dll是vc 9.0编译的。

最好装好pywin32,以便支持ISAPI,还有可能的话装上wsgiref。

祝大家好运。

 

本文来自CSDN博客,转载请标明出处:http://blog.csdn.net/huyoo/archive/2009/12/30/5108673.aspx

posted @ 2009-12-30 21:14  Neo.Yan  阅读(555)  评论(0编辑  收藏  举报