简单配置apache http server + python cgi的例子
OS: windows XP Apache 版本:apache_2.2.10-win32-x86-no_ssl.msi 一路点next,完成安装apache。期间需要输入domain和webmaster email之类的东西,随便填就可以了,以后用的到时候再改。 完成安装之后,打开浏览器,输入本地地址或者回环地址“127.0.0.1”,会显示出“It works!”字符串,说明安装OK了,如果没有出现这个信息,那就卸载重新安装试试吧! 下面开始配置自己的root文件夹了,具体怎么配,可以查阅apache的官方文档http://httpd.apache.org/docs/2.2/ 先打开conf/httpd.conf文件,这个就是核心的配置文件。添加下面的内容: Alias /xml "D:/voip/xmlroot/html"
" print "Running:" print "Python %s
" %(sys.version) print "Environmental variables:
" print "
-
" for k in sorted(os.environ): print "
-
%s:\t\t%s
" %(cgi.escape(k), cgi.escape(os.environ[k])) print "
" print 'Parameters: ' fs = cgi.FieldStorage() for k in fs.keys(): print ' %s=%s' %(k, fs[k].value) print "" print "" 保存为test.py。在浏览器中输入127.0.0.1/cgi-bin/test.py ,如果前面的步骤没有出错的话,应该可以看到类似于下面的信息: Running: Python 2.5.2 (r252:60911, Feb 21 2008, 13:11:45) [MSC v.1310 32 bit (Intel)] Environmental variables: COMSPEC: C:\WINDOWS\system32\cmd.exe DOCUMENT_ROOT: D:/Program Files/Apache Software Foundation/Apache2.2/htdocs GATEWAY_INTERFACE: CGI/1.1 HTTP_ACCEPT: application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5 HTTP_ACCEPT_CHARSET: GBK,utf-8;q=0.7,*;q=0.3 HTTP_ACCEPT_ENCODING: gzip,deflate,bzip2,sdch HTTP_ACCEPT_LANGUAGE: zh-CN,zh;q=0.8 HTTP_CONNECTION: keep-alive HTTP_HOST: 192.168.1.190 HTTP_USER_AGENT: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US) AppleWebKit/530.5 (KHTML, like Gecko) Chrome/2.0.172.28 Safari/530.5 PATH: C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\Program Files\Intel\DMIX;D:\Program Files\TortoiseSVN\bin;D:\cygwin\bin;C:\Program Files\Common Files\Adobe\AGL;;C:\Program Files\SinoVoice\jTTS 5.0 Desktop\Bin PATHEXT: .COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH QUERY_STRING: REMOTE_ADDR: 192.168.1.190 REMOTE_PORT: 2667 REQUEST_METHOD: GET REQUEST_URI: /cgi-bin/test.py SCRIPT_FILENAME: D:/voip/xmlroot/cgi-bin/test.py SCRIPT_NAME: /cgi-bin/test.py SERVER_ADDR: 192.168.1.190 SERVER_ADMIN: tt@tony.com SERVER_NAME: 192.168.1.190 SERVER_PORT: 80 SERVER_PROTOCOL: HTTP/1.1 SERVER_SIGNATURE: SERVER_SOFTWARE: Apache/2.2.10 (Win32) SYSTEMROOT: C:\WINDOWS WINDIR: C:\WINDOWS python程序的第一行一定要写上python解释器安装的绝对路径,否则http server也不知道如何处理这个脚本程序。例子中的路径为: #!D:/Python25/python.exe
欢迎大佬支持本博客的发展 -- Donate --
本文链接:简单配置apache http server + python cgi的例子
转载声明:本站文章若无特别说明,皆为原创,转载请注明来源:三十岁,谢谢!^^
分享到: | |
没有通告