zoukankan      html  css  js  c++  java
  • Linux Python apache的cgi配置

    一、找到安装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

  • 相关阅读:
    我与ARM的那些事儿1初识ARM
    WP的万能小应用时钟表
    单片机的模拟智能灌溉系统
    android的计算器
    C语言经典面试题目(转的,不过写的的确好!)
    数据库sqlite3在linux中的使用
    认识域模型
    认识JMS
    认识JDOM
    认识RMI
  • 原文地址:https://www.cnblogs.com/myvic/p/6821368.html
Copyright © 2011-2022 走看看