browser <==> webserver <==> cgi program
以前还真没认真去看下CGI到底如何工作的。其实很简单:
1. webserver 接到请求,则 create process 去执行 cgi program
2. 将一些参数作为'环境变量'传给 cgi program
3. cgi program 处理完逻辑后,把生成的网页写到 stdout
4. webserver 把 stdout 的内容丢给 browser
不过 nginx 不支持"create process 去执行 cgi program",所以就不演示了。
这有个更详细的说明,直接贴出来:
1. For each request, the server creates a new process and the process initializes itself.
2. The Web server passes the request information (such as remote host, username, HTTP headers, etc.) to the CGI program in environment variables.
3. The Web server sends any client input (such as user-entered field values from an HTML form) to the CGI program's standard input.
4. The CGI program writes any output to be returned to the client on standard output. Error information written to standard error is logged by the Web server.
5. When the CGI process exits, the request is complete.
评论