英文:
Go (golang) direct output to Nginx
问题
对于使用Nginx与Go,我通常看到的解决方案是使用Nginx的fastcgi_pass和Go的"net/http/fcgi"。
然而,我想知道在这里使用Go的http功能是否多余。由于Nginx会将响应输出为http响应,所以是否可以简单地将Go脚本返回的字符串传递给Nginx,让Nginx创建http响应?
对于底层工作流程和性能影响的进一步解释将不胜感激。
英文:
For using Nginx with Go, the solution I see normally is using Nginx's fastcgi_pass and Go's "net/http/fcgi".
However I wonder if the use of Go's http facility is redundant here. Since Nginx would output the response as http response, can one simply pass the strings return from the Go script to Nginx and let Nginx create the http response?
Any further explanations about the underlying workflow and performance implication would be greatly appreciated.
答案1
得分: 1
我从未真正使用fastcgi进行部署,尽管我曾经协助过一个功能性示例。就性能而言,我会对fcgi部署进行基准测试,并与反向代理设置进行比较。
英文:
I've never made use of fastcgi for an actual deployment though I assisted with a functional example once. As far as performance, I'd benchmark an fcgi deployment against a reverse proxy setup and compare.
答案2
得分: 1
你读过FactCGI规范了吗?它明确定义了FastCGI服务器和客户端如何进行交互:
3.3 记录
应用程序使用一种简单的协议从Web服务器执行请求。协议的细节取决于应用程序的角色,但大致上,Web服务器首先将参数和其他数据发送给应用程序,然后应用程序将结果数据发送给Web服务器,最后应用程序向Web服务器发送请求完成的指示。
所有通过传输连接流动的数据都包含在FastCGI记录中。FastCGI记录实现了两个功能。首先,记录在几个独立的FastCGI请求之间复用传输连接。这种复用支持能够使用事件驱动或多线程编程技术处理并发请求的应用程序。其次,记录在单个请求中的每个方向上提供了几个独立的数据流。这样,例如,stdout和stderr数据可以通过单个传输连接从应用程序传递到Web服务器,而不需要单独的连接。
typedef struct { unsigned char version; unsigned char type; unsigned char requestIdB1; unsigned char requestIdB0; unsigned char contentLengthB1; unsigned char contentLengthB0; unsigned char paddingLength; unsigned char reserved; unsigned char contentData[contentLength]; unsigned char paddingData[paddingLength]; } FCGI_Record;
FastCGI记录由固定长度的前缀和可变数量的内容和填充字节组成。
...
正如你所看到的,这是一种二进制协议,与HTTP有很大的不同。
英文:
Did you read the FactCGI spec? It explicitly defines how FastCGI server and clients pefrorm their exchange:
> 3.3 Records
>
> Applications execute requests from a Web server using a simple protocol. Details of the protocol depend upon the application's role, but roughly speaking the Web server first sends parameters and other data to the application, then the application sends result data to the Web server, and finally the application sends the Web server an indication that the request is complete.
>
> All data that flows over the transport connection is carried in FastCGI records. FastCGI records accomplish two things. First, records multiplex the transport connection between several independent FastCGI requests. This multiplexing supports applications that are able to process concurrent requests using event-driven or multi-threaded programming techniques. Second, records provide several independent data streams in each direction within a single request. This way, for instance, both stdout and stderr data can pass over a single transport connection from the application to the Web server, rather than requiring separate connections.
>
> typedef struct {
> unsigned char version;
> unsigned char type;
> unsigned char requestIdB1;
> unsigned char requestIdB0;
> unsigned char contentLengthB1;
> unsigned char contentLengthB0;
> unsigned char paddingLength;
> unsigned char reserved;
> unsigned char contentData[contentLength];
> unsigned char paddingData[paddingLength];
> } FCGI_Record;
>
> A FastCGI record consists of a fixed-length prefix followed by a variable number of content and padding bytes.
>
> …
As you can see, it's a binary protocol, rather different from HTTP.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论