Web服务器CGI的配置

Web服务器CGI的配置

CGI程序运行在Web服务器端,Web服务器可以是Apache,Nginx等

GGI程序可以是Python,Ruby,Perl,Shell,C/C++等

结构原理如下

配置

apache默认加载cgi模块(若没加载,先加载):

LoadModule cgi_module modules/mod_cgi.so

修改httpd.conf配置中的以下内容:


#1.在Options中添加ExecCGI的选项

<Directory "D:/wamp/www/">
  ...
    Options Indexes FollowSymLinks ExecCGI
    ...
</Directory>

#2.在AddHandler中添加可执行的程序类型(.py)

    # AddHandler allows you to map certain file extensions to "handlers":
    # actions unrelated to filetype. These can be either built into the server
    # or added with the Action directive (see below)
    #
    # To use CGI scripts outside of ScriptAliased directories:
    # (You will also need to add "ExecCGI" to the "Options" directive.)
    #
    AddHandler cgi-script .cgi .py .pl

注意:以下的内容部分不需要修改
<Directory "D:/wamp/bin/apache/apache2.4.9/cgi-bin">
    AllowOverride None
    Options None
    Require all granted
</Directory>

编写CGI程序

  • Python CGI
#!D:\Anaconda2\python.exe
print "Content-type:text/html"
print                           # 空行,告诉服务器头部结束
print '<html>'
print '<head>'
print '<meta charset="utf-8">'
print '<title>Hello Word - 我的第一个 CGI 程序!</title>'
print '</head>'
print '<body>'
print '<h2>Hello Word! 我是来自菜鸟教程的第一CGI程序</h2>'
print '</body>'
print '</html>'

# ### 注意:
# 1,第一行Python的执行路径一定要写对
# 2,第二行和第三行必不可少

参考

PythonCGI编程

Wamp支持Python CGI

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值