cgi配置:apache2.4与apache2.2区别

相同点:

1.在安装目录apache下找到文件httpd.conf,检查以下代码是否前面有#,如果有就去掉

LoadModule cgi_module modules/mod_cgi.so


2.查看并修改一下代码中的路径,与下面的第4点中的路径一致

ScriptAlias /cgi-bin/ "D:/SoftWare/XAMPP/cgi-bin/"


3.找到一下代码添加.py .exe等你需要的执行文件格式

AddHandler cgi-script .cgi .pl .asp .py .exe


不同点:
4.找到类似下面的代码块(里面的路径改为自己的安装路径,我这里是一个集成环境)

#
# "D:/SoftWare/XAMPP/cgi-bin" should be changed to whatever your ScriptAliased
# CGI directory exists, if you have that configured.
#
<Directory "D:/SoftWare/XAMPP/cgi-bin">
    AllowOverride None
    Options None
    Require all granted
</Directory>

apache2.4修改为:

<Directory "D:/SoftWare/XAMPP/cgi-bin">
    AllowOverride None
    Options Indexes FollowSymLinks ExecCGI
    Require all granted 
    Require host ip
</Directory>

在apache2.2中则改为

<Directory "D:/SoftWare/XAMPP/cgi-bin">
   AllowOverride None
   Options +ExecCGI
   Order allow,deny
   Allow from all
</Directory>

5.举一个python的例子,创建文件hello.py,文件内容如下:

注意:注释中的路径一定要改好

#!D:\SoftWare\python3.6\python.exe    #linux一般为#!usr/bin/python
# -*- coding: utf-8 -*-
print "Content-type:text/html"
print                               # 空行,告诉服务器结束头部
print '<html>'
print '<head>'
print '<meta charset="utf-8">'
print '<title>Hello Word!</title>'
print '</head>'
print '<body>'
print '<h2>Hello Word!</h2>'
print '</body>'
print '</html>'
将该文件放到cgi-bin目录下,
浏览器输入localhost/cgi-bin/hello.py


结果:




  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值