CGI, FastCGI, SCGI and WSGI
目录

对CGI, FastCGI, SCGI, WSGI一些资料查阅后的理解,可能不准确。

CGI

Web Server作为HTTP Server收到HTTP Request, 然后通过静态文件或者动态脚本生成内容返回HTTP Response。

Common Gateway Interface (CGI), 在Web Server(Apache, nginx)和Web Application之前提供接口, 传输产生的动态Web内容。

Web Server   <-- CGI -->  Web App

比如在Web Server下的cgi-bin/目录里存放CGI程序,常用的是.cgi结尾的文件。

CGI通过Web Server进行fork/exec的方式创建新的进程来处理请求内容, 如果新的程序是脚本还可能需要编译。 新的进程再通过socket或stdout写回到Web Server。 原始的方式每个是每个Request都创建新的进程进行处理。

几个CGI变体:

  • Simple Common Gateway Interface(SCGI)
  • Web Server Gateway Interface(WSGI)
  • FastCGI(FCGI)

非CGI体系:

  • Java Servlet/JSP

FastCGI

Web App以Daemon方式运行,FastCGI以Socket方式连接Web Server和Web App。

SCGI

SCGI像FastCGI相似,但是通过IPC方式连接Web Server和Web App。

有种理解是SCGI更容易实现,FastCGI有更好的性能。

WSGI

WSGI是面向Python的Web App接口标准。 WSGI是Python API,以Python Module作为Web App。 WSGI可以有两种调用方式:

  1. Embedded:Python Module可以被Python Web Server直接调用,或Apache通过mod_wsgimod_python调用,这些都无需创建新的进程;
  2. Daemon:Apache使用mod_wsgimod_fastcgi以IPC方式和WSGI Daemon通信。
Apache -> mod_fastcgi -> FLUP (via CGI protocol) -> Django (via WSGI protocol)

Reference

发表评论