码迷,mamicode.com
首页 > 其他好文 > 详细

Nginx+FastCgi的测试

时间:2015-06-09 20:05:45      阅读:205      评论:0      收藏:0      [点我收藏+]

标签:

Nginx + Fastcgi配置方法

一、nginx安装&配置

1) apt-get install nginx
2) 修改/etc/nginx/sites-available下的default文件

</pre><pre name="code" class="plain">#设置首页
root /usr/share/nginx/myweb;
index index.html index.htm;

#修改端口
listen 8880 default_server;
listen [::]:8880 default_server ipv6only=on;

#设置fastcgi程序入口
location /mycgi.cgi {
        fastcgi_pass 127.0.0.1:9999;	 -> fastcgi程序监听的端口
        #fastcgi_index mycgi.out;
        include fastcgi_params;
}

二、fastcgi管理器spawn-fcgi的安装

 apt-get install spawn-fcgi

三、fcgi库的安装

没有找到官网下载,有些奇怪,临时参照附件。

1)修改include/fcgio.h文件,追加#include <cstdio>
2)./configure
3)./make install
4)  ldconfig /usr/local/lib   (libfcgi.so默认生成路径)

四、编译cgi程序

例子代码如下:

	#include <iostream>
	#include <fcgi_stdio.h>
	#include <stdlib.h>
	#include <sys/types.h>
	#include <unistd.h>

	int main(int argc, char** argv)
	{
	    int count = 0;

	    while( FCGI_Accept() >= 0 )
	    {
	        printf( "Content-type:text/html\r\n\r\n" );
	        printf( "<p> Hello FastCGI !  </ p>" );
	        printf( "<br /> Request number = [%d]", ++count );
	        printf( "<br /> CGI PID: %d ", getpid() );

	    }

	    return 0;
	}

编译

g++ mycgi.c -o mycgi.out -L /usr/local/lib -lfcgi

五、启动cgi

spawn-fcgi -a 127.0.0.1 -p 9999 -f /root/mycgi/mycgi.out -F 3
-F指定启动的cgi进程个数,nginx会轮询访问
访问http://server:8880即可看到cgi程序的输出。

Nginx+FastCgi的测试

标签:

原文地址:http://blog.csdn.net/ydogg/article/details/46430527

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!