您的位置:首页 > 理论基础 > 计算机网络

apache设置相关:python写CGI http/put目录

2012-01-03 16:45 351 查看
python编写cgi脚本

参考:http://www.tutorialspoint.com/python/python_cgi_programming.htm

1.在apache上设置cgi脚本目录,在http.conf加入下列配置并重启apache

<Directory "/var/www/bin-cgi/">
AllowOverride None
Options ExecCGI
Order allow,deny
Allow from all
</Directory>
AddHandler cgi-script .py


2.编写python的cgi程序

/var/www/bin-cgi/pythoncgi.py

#!/usr/bin/python
print "Content-type:text/html\r\n\r\n"
print '<html>'
print '<head>'
print '<title>Hello World - First CGI Program</title>'
print '</head>'
print '<body>'
print '<h2>Hello World! This is my first CGI program</h2>'
print '</body>'
print '</html>'


3.通过浏览器访问http://localhost/pythoncgi.py可以看到结果

PS:以上只是一个简单的demo,实际应用都会引入python的cgi模块,可以更方便的解析url参数、环境变量等

另,据说apache的扩展模块mod_python更适合用python编写cgi脚本

设置http/put目录

在http.conf中加入如下配置,即可用http的put方法往/var/www/putdir/目录传文件和写数据

<Directory "/var/www/putdir/">
Dav On
AllowOverride None
Options All
Order allow,deny
Allow from all
</Directory>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: