您的位置:首页 > 运维架构 > Apache

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

2017-05-16 15:03 423 查看
相同点:

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

结果:
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  web server 前端