我试图在Nginx Web服务器后面运行用C语言编写的fastcgi应用程序.Web浏览器永远不会完成加载,响应永远不会完成.我不知道如何处理和调试.任何见解将不胜感激.
hello world应用程序取自fastcgi.com并简化为如下所示:
#include "fcgi_stdio.h"
#include <stdlib.h>
int main(void)
{
while(FCGI_Accept >= 0)
{
printf("Content-type: text/html\r\nStatus: 200 OK\r\n\r\n");
}
return 0;
}
Run Code Online (Sandbox Code Playgroud)
输出可执行文件使用以下任一项执行:
cgi-fcgi -connect 127.0.0.1:9000 a.out
要么
spawn-fcgi -a120.0.0.1 -p9000 -n ./a.out
Nginx配置是:
server {
listen 80;
server_name _;
location / {
# host and port to fastcgi server
root /home/user/www;
index index.html;
fastcgi_pass 127.0.0.1:9000;
}
}
Run Code Online (Sandbox Code Playgroud)
Sin*_*nür 16
你需要FCGI_Accept在while循环中调用:
while(FCGI_Accept() >= 0)
Run Code Online (Sandbox Code Playgroud)
你FCGI_Accept >= 0的代码中有.我认为这会导致FCGI_Accept与之比较的函数的地址0.由于函数存在,因此比较永远不会为false,但不会调用该函数.
这是nginx,ubuntu,c ++和fastcgi的一个很好的例子.
http://chriswu.me/blog/writing-hello-world-in-fcgi-with-c-plus-plus/
如果你想运行他的代码,我已经将它放入带有指令的git仓库中.您可以查看并自行运行.我只在Ubuntu上测试过它.
https://github.com/homer6/fastcgi
| 归档时间: |
|
| 查看次数: |
19774 次 |
| 最近记录: |