CGI

来自维基百科

In computing, Common Gateway Interface (CGI) offers a standard protocol for web servers to execute programs that execute like Console applications (also called Command-line interface programs) running on a server that generates web pages dynamically. Such programs are known as CGI scripts or simply as CGIs. The specifics of how the script is executed by the server are determined by the server.[1] A CGI script essentially reads a query string and produces a HTML page.[2]

CGI接口定义了server如何执行脚本并返回一个HTML页面.

实际上, 在网络发展早期, 浏览器向服务器发送HTTP请求, 首先会到达Http Web Software, 如IIS, Apache, Nginx, Node-js服务器等. 然后这些服务器捕获了这些HTTP请求, 会解析出请求的内容, 并将具体的请求内容调用一些脚本或者程序, 执行完之后会组成html的输出, 返回给client端. CGI就是HTTP请求通过服务器软件传给脚本的接口定义.

This is usually done by marking a directory within the document collection as containing CGI scripts - its name is often cgi-bin. For example, /usr/local/apache/htdocs/cgi-bin could be designated as a CGI directory on the web server. When a Web browser requests a URL that points to a file within the CGI directory (e.g., http://example.com/cgi-bin/printenv.pl/with/additional/path?and=a&query=string), then, instead of simply sending that file (/usr/local/apache/htdocs/cgi-bin/printenv.pl) to the Web browser, the HTTP server runs the specified script and passes the output of the script to the Web browser. That is, anything that the script sends to standard output is passed to the Web client instead of being shown on-screen in a terminal window.

由web server执行脚本, 但这里的脚本或者软件, 都应该是命令行的, 在web server中会有一个目录(虚拟, 总之是一个Dict结构, 映射了url和script的对应关系), 如果收到client的对文件的请求, web server就会把本来返回脚本文件的行为变为执行脚本, 然后返回脚本输出到标准输出的内容, 并返回给client.

As remarked above, the CGI standard defines how additional information passed with the request is passed to the script. For instance, if a slash and additional directory name(s) are appended to the URL immediately after the name of the script (in this example, /with/additional/path), then that path is stored in the PATH_INFO environment variable before the script is called. If parameters are sent to the script via an HTTP GET request (a question mark appended to the URL, followed by param=value pairs; in the example, ?and=a&query=string), then those parameters are stored in the QUERY_STRING environment variable before the script is called. If parameters are sent to the script via an HTTP POST request, they are passed to the script's standard input. The script can then read these environment variables or data from standard input and adapt to the Web browser's request.[10]

这里还涉及到对于HTTP请求方式的不同, 上面的例子上是当请求server software的脚本文件时,

请求是

http://example.com/cgi-bin/printenv.pl/with/additional/path?and=a&query=string

如果是HTTP GET请求, 在请求脚本文件后还加了/with/additional/path, 这个会被保存在一个环境变量中PATH_INFO中, 而后面的请求参数也会被保存在一个环境变量QUERY_STRING中.

如果是HTTP POST请求, 在HTTP请求体里面的参数会被重定向到脚本的标准输入, 然后执行脚本.

FastCGI

FastCGI是CGI的一个变种, 是一个二进制协议, 目的在于减少server software和CGI pragrams的过度交互, 并使server可以一次处理多个请求. CGI Application是one request, one process, 效率比较低.

FastCGI可以认为是web server和application的中间层, FastCGI有一个一直存在的service process, 通过socket, pipe或者是TCP和web server的进程通信, 会不断把请求参数传递给application.

Python WSGI

WSGI(Web Server GateWay Interface)

在CGI和FastCGI之上, Python实现了WSGI, 作为对于使用Python开发web application时同web server的接口. WSGI中有middleware的概念, 类似于FastCGI, 也是中间层.

cgi_and_fastcgi的更多相关文章

随机推荐

  1. 3-3Java程序的结构

    这是类的定义 这是主方法的定义 类里面包含一个主方法,或者是主方法嵌套到我们的类里面 大括号要特别注意,通过大括号我们可以看到类和主方法的包含关系 class后面一定是跟的类的名字

  2. c#静态多态性与动态多态性

    C# 多态性 多态性意味着有多重形式.在面向对象编程范式中,多态性往往表现为"一个接口,多个功能". 多态性可以是静态的或动态的.在静态多态性中,函数的响应是在编译时发生的.在动态 ...

  3. 让App飞久一点

    此文已由作者杨晓授权网易云社区发布. 欢迎访问网易云社区,了解更多网易技术产品运营经验. 本文从作者所在项目进行的耗电量测试入手,介绍了移动端App耗电量测试的一些基本概念和方法,重点介绍了iOS应用 ...

  4. 萌新学习图的强连通(Tarjan算法)笔记

    --主要摘自北京大学暑期课<ACM/ICPC竞赛训练> 在有向图G中,如果任意两个不同顶点相互可达,则称该有向图是强连通的: 有向图G的极大强连通子图称为G的强连通分支: Tarjan算法 ...

  5. poj2133(sg函数)

    关于sg函数:http://www.cnblogs.com/Knuth/archive/2009/09/05/1561007.html 题目链接:http://poj.org/problem?id=2 ...

  6. [Xcode 实际操作]九、实用进阶-(11)系统本地通知的创建和使用

    目录:[Swift]Xcode实际操作 本文将演示系统本地通知的创建和使用. 在项目导航区,打开视图控制器的代码文件[ViewController.swift] import UIKit //引入需要 ...

  7. 网络工程师HCNA认证学习笔记Day1

    企业网络 企业网络远程互联是广域网WAN互联,而非互联网Internet小型企业网络:一个路由器.交换机.AP大型企业网络:核心层.汇聚层.接入层.考虑可用性.稳定性.扩展性.安全性.可管理,冗余. ...

  8. SpringBoot2.0基础案例(01):环境搭建和RestFul风格接口

    一.SpringBoot 框架的特点 1.SpringBoot2.0 特点 1)SpringBoot继承了Spring优秀的基因,上手难度小 2)简化配置,提供各种默认配置来简化项目配置 3)内嵌式容 ...

  9. hyperledger fabric 1.0.5 分布式部署 (六)

    如何在相同的peer 节点上创建多个 channel 作者在hyperledger fabric 1.0.5 分布式部署 (五)已经向读者们介绍了一个简单的fabric 的部署流程,那么根据上一篇博客 ...

  10. 黑马方法引用学习 Stream流 函数式接口 Lambda表达式 方法引用