IIS上通过python的CGI模块 执行python脚本

一、首先要在Win7下安装好IIS

细节访问http://wenku.baidu.com/view/148ab53567ec102de2bd89d2.html


Python学习简明教程:

http://sebug.NET/paper/python/index.html#userconsent#


具体步骤如下:

1、确保你的操作系统里已经有了IIS!

运行——%windir%\system32\OptionalFeatures.exe

或者——via pointy-clicky: Start...Control Panel...Programs and Features... (and then on the left hand side) Turn Windows Features on or Off. Make sure CGI is installed, under the IIS node.

2、在控制面板-打开或者关闭Windows功能,检查系统打开或者关闭的功能,安装好需要安装的系统功能。如下图中的功能必须启用

IIS上通过python的CGI模块 执行python脚本_第1张图片

3、出现安装Windows功能的选项菜单,注意选择的项目,手动选择需要的功能,按下图安装所需服务即可。

IIS上通过python的CGI模块 执行python脚本_第2张图片

4、功能安装完成后,再次进入控制面板,选择管理工具,双击Internet(IIS)管理器选项,进入IIS设置。

IIS上通过python的CGI模块 执行python脚本_第3张图片

二、配置IIS服务器

5、进入到IIS7控制面板

IIS上通过python的CGI模块 执行python脚本_第4张图片

6、IIS7中ASP 父路径 是没有启用的,要 开启父路径,选择True,搞定父路径选项。

7、展开连接列表项,新建一个名称为MockP70的网站。

在本地硬盘目录创建一个存储网站信息的物理路径,如下图所示:

IIS上通过python的CGI模块 执行python脚本_第5张图片

填写网站名称,选择网站的物理路径,并为其设置一个端口8088

IIS上通过python的CGI模块 执行python脚本_第6张图片

点击确定,完成网站的建立。

8、在网站的本地目录下创建一个名为cgi-bin的目录,回到IIS服务器管理,刷新就可以看到网站下已经有了你新创建的文件夹。

IIS上通过python的CGI模块 执行python脚本_第7张图片

IIS上通过python的CGI模块 执行python脚本_第8张图片


9、配置IIS7的站点

给网站添加应用程序

IIS上通过python的CGI模块 执行python脚本_第9张图片

IIS上通过python的CGI模块 执行python脚本_第10张图片

点击确定按钮,可以看到cgi-bin成了网站文件

IIS上通过python的CGI模块 执行python脚本_第11张图片

为网站添加处理程序映射

IIS上通过python的CGI模块 执行python脚本_第12张图片

添加脚本映射

IIS上通过python的CGI模块 执行python脚本_第13张图片

IIS上通过python的CGI模块 执行python脚本_第14张图片

IIS上通过python的CGI模块 执行python脚本_第15张图片

IIS上通过python的CGI模块 执行python脚本_第16张图片

注意啊!!!一定要选择是!!!否则要自己再去设置ISAPI和CGI显示,很是麻烦啊!


脚本映射成功!

IIS上通过python的CGI模块 执行python脚本_第17张图片

检查在cgi-bin文件夹下自动生成的web.xml文件,内容如下:

IIS上通过python的CGI模块 执行python脚本_第18张图片

要重启IIS,保证能够正常使用。

【重启方法】

在命令行输入:iisreset/start


编写测试Python的文件

在cgi-bin目录下创建如下三个python文件,内容分别如下图所示:

IIS上通过python的CGI模块 执行python脚本_第19张图片IIS上通过python的CGI模块 执行python脚本_第20张图片IIS上通过python的CGI模块 执行python脚本_第21张图片IIS上通过python的CGI模块 执行python脚本_第22张图片


在MockP70目录下创建test01.html文件,内容如下图所示:

IIS上通过python的CGI模块 执行python脚本_第23张图片

IIS上通过python的CGI模块 执行python脚本_第24张图片


完成啦!去测试吧!

在Web浏览器中输入

http://localhost:8088/test01.html


点击三个超链接分别显示如下三张图:





【附加学习知识点】

windows系统的看这篇: 
http://stackoverflow.com/questions/6823316/python-on-iis-how 

Linux核心的看这篇: 
http://docs.python.org/2/howto/webservers.html 

IIS上通过python的CGI模块 执行python脚本_第25张图片

  1. Open IIS manager. Run %windir%\system32\inetsrv\iis.msc, or do this via the control panel: Start...Control Panel...Administrative Tools...Internet Information Services (IIS) Manager. Create a new application(添加新的应用程序). Specify the virtual path(别名) as /py and the physical path(物理路径) as c:\dev\python.


  2. Within that IIS application(处理程序映射), add a script map(脚本映射) for *.py, and map it to c:\python27\python.exe %s %sIIS上通过python的CGI模块 执行python脚本_第26张图片

你可能感兴趣的:(python)