一、找到安装Apache的目录/usr/local/apache2/conf,并对httpd.conf配置文件进行修改

1.加载cgi模块

去掉注释:

LoadModule cgid_module modules/mod_cgid.so  #//当使用内置模块prefork.c 时动态加载cgi_module

LoadModule cgi_module modules/mod_cgi.so   #当使用内置模块worker.c 时动态加载cgid_module

2.设置cgi脚本文件路径

ScriptAlias /cgi-bin/ "/var/www/cgi-bin/"

3.设置cgi路径的访问权限

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

4.设置apache可解释python的cgi脚本文件

AddHandler cgi-script .cgi .py

这些配置好后,重启apaache

二、添加CGI脚本文件

在/var/www/cgi-bin/目录下,创建hello.py文件,添加如下代码,复制给他chmod 755 hello.py 的权限

#!/usr/bin/env python
# -*- coding: UTF-8 -*- print "Content-type:text/html"
print
print '<html>'
print '<head>'
print '<title>Hello</title>'
print '</head>'
print '<body>'
print '<h2>Hello Word! This is my first CGI program</h2>'
print '</body>'
print '</html>'

三步,通过浏览器访问

localhost/cgi-bin/hello.py

参考文档:http://xpleaf.blog.51cto.com/9315560/1740221

http://www.runoob.com/python/python-cgi.html

Linux Python apache的cgi配置的更多相关文章

  1. 分享:linux下apache服务器的配置和管理

    linux下apache服务器的配置和管理. 一.两个重要目录: Apache有两个重要的目录:1.配置目录/etc/httpd/conf:2.文档目录/var/www: 二.两种配置模式: Apac ...

  2. Linux下Apache虚拟主机配置

    Linux下Apache虚拟主机的三种配置.这样可以实现一台主机架构多个独立域名网站.其中基于域名的最为常见.性价比也最高.下面PHP程序员雷雪松详细的讲解下Linux下Apache虚拟主机配置的具体 ...

  3. Linux服务器---apache支持cgi

    Apache支持cgi  1.打开Apache配置文件httpd.conf,搜索“cgi”,找到下面的一段,去掉“addhandler”前面的“#“,这样就开启了Apache的cgi功能 [root@ ...

  4. Linux下apache+phppgadmin安装配置

    1.安装pg 安装PostgreSQL数据库 修改pg_hba.conf配置文件,使得数据库可以通过外部访问. 具体可以配置为: # TYPE DATABASE USER ADDRESS METHOD ...

  5. linux下apache+php搭建配置记录

    第1章  环境说明1.1 系统说明Centos 6.2 (最小化安装)1.2 软件说明httpd-2.4.2.tar.gzapr-util-1.4.1.tar.gzapr-1.4.6.tar.gzpc ...

  6. Linux下apache支持PHP配置

    https://www.cnblogs.com/qiuxiao/p/6815350.html https://www.cnblogs.com/polestar/p/6086552.html

  7. Python+Apache+CGI完全配置

    http://www.tuicool.com/articles/jIZfaqQ 操作系统环境:Ubuntu 15.10 0.需求原因 想在我的Linux上架设Apache来运行CGI程序,方便以后用A ...

  8. 吴裕雄--python编程:CGI编程

    什么是CGI CGI 目前由NCSA维护,NCSA定义CGI如下: CGI(Common Gateway Interface),通用网关接口,它是一段程序,运行在服务器上如:HTTP服务器,提供同客户 ...

  9. Linux下apache+phppgadmin+postgresql安装配置

    Linux下apache+phppgadmin+postgresql安装配置 操作系统:CentOS 安装包:httpd(首选yum), php(包括php以及php-pgsql,php-mbstri ...

随机推荐

  1. BZOJ4259:残缺的字符串——题解

    https://www.lydsy.com/JudgeOnline/problem.php?id=4259 很久很久以前,在你刚刚学习字符串匹配的时候,有两个仅包含小写字母的字符串A和B,其中A串长度 ...

  2. HDU5115:Dire Wolf——题解+翻译

    http://acm.hdu.edu.cn/showproblem.php?pid=5115 题目大意:给n匹狼,每一次攻击可以秒杀一匹狼,但同时会受到这匹狼的a攻击和它相邻两只狼的b攻击. 给定a, ...

  3. HDU4812 D tree 【点分治 + 乘法逆元】

    D树 时间限制:10000/5000 MS(Java / Others)内存限制:102400/102400 K(Java / Others) 总共提交5400个已接受的提交1144 问题描述 南京理 ...

  4. nodejs路径处理方法和绝对路径

    1. 路径处理方法 __dirname 表示当前文件所在的目录的绝对路径__filename 表示当前文件的绝对路径module.filename ==== __filename 等价process. ...

  5. 背景建模技术(二):BgsLibrary的框架、背景建模的37种算法性能分析、背景建模技术的挑战

    背景建模技术(二):BgsLibrary的框架.背景建模的37种算法性能分析.背景建模技术的挑战 1.基于MFC的BgsLibrary软件下载 下载地址:http://download.csdn.ne ...

  6. 自己做的jquery的autocomplete的一个例子

    转载自:http://dada-fangfang.iteye.com/blog/695464 首先下载jquery.js和jquery.autocomplete.js 注意:jquery.js 要放在 ...

  7. 关于$.data(element,key,value)与ele.data.(key,value)的区别

    <!doctype html> <html> <head> <meta charset="utf-8"> <title> ...

  8. 在此位置打开CMD

    Windows Registry Editor Version 5.00 [HKEY_CLASSES_ROOT\folder\shell\cmd]@="在此位置打开CMD"[HKE ...

  9. 洛谷P2901 [USACO08MAR]牛慢跑Cow Jogging

    题目描述 Bessie has taken heed of the evils of sloth and has decided to get fit by jogging from the barn ...

  10. Go从入门到精通(持续更新)

    1.0 搭建环境 由于我们 Go官方网站 在我大天朝被和谐了,所以我们只能去 Go语言中文网 来下载了.Go的安装很简单,不像Java还要配置一大堆的东西,选择自己系统的对应版本,下载安装,像安装QQ ...