python模块cgihttpserver启动

  • cgi是web服务器运行web应用的一种机制,web服务器通过执行cgi脚本,然后将该程序的标准输出作为http响应的一部分
  • CGIHTTPServer是python标准模块的web服务器,它可以运行cgi程序
  • mkdir cgi-bin,待运行文件必须位于cgi-bin目录下
  • vim hello.py
  • #!/usr/bin/env python2
    print "200 ok"
    print "Content-Type: text/plain"
    print ""
    print "Hello World"

  • chmod a+x hello.py
  • python -m CGIHTTPServer 8000  启动时,cd到cg0-bin目录下,他就会把这个目录作为服务启动起来
  • [root@localhost cgi-bin]# python2 -m CGIHTTPServer 8001
    Serving HTTP on 0.0.0.0 port 8001 ...

原文地址:https://www.cnblogs.com/mmdln/p/9019690.html