Nginx+FastCgi的测试

网络 网络管理 网络运维
您知道Nginx和Fastcgi的配置方法吗?本文为您介绍Nginx + Fastcgi配置方法,希望对您有所帮助。

Nginx + Fastcgi配置方法

一、nginx安装&配置

1) apt-get install nginx

2) 修改/etc/nginx/sites-available下的default文件

[plain] view plaincopy
#设置首页
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

2)./configure

3)./make install

4) ldconfig /usr/local/lib (libfcgi.so默认生成路径)

四、编译cgi程序

例子代码如下:

[cpp] view plaincopy#include
#include
#include
#include
#include
int main(int argc, char** argv)
{
int count = 0;
while( FCGI_Accept() >= 0 )
{
printf( "Content-type:text/html\r\n\r\n" );
printf( " Hello FastCGI ! " );
printf( " Request number = [%d]", ++count );
printf( " 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程序的输出。

责任编辑:何妍 来源: CSDN博客
相关推荐

2017-05-18 13:33:16

Web服务器编译部署

2010-03-29 16:58:41

Nginx FastC

2010-03-29 10:38:36

Nginx配置

2013-04-25 10:01:35

Nginx

2017-12-28 10:22:28

NginxFastCGIPHP-fpm

2011-11-28 21:56:41

2014-07-23 09:55:39

NginxLibreSSL

2017-07-19 16:58:53

PHPFastCGI 内核探索

2010-03-29 15:13:23

Nginx反向代理

2012-02-16 10:18:04

Nginx压力测试

2014-03-28 14:20:04

2009-06-30 09:50:10

IIS下配置PHPISAPIFastCGI

2014-01-17 10:38:07

Cache服务降级

2009-10-14 09:57:51

pinyshop

2012-07-20 14:48:54

Nginx测试

2014-11-24 09:35:06

CGIFastCGIWSGI

2015-10-12 09:13:02

PHPFastCGI mod_php

2010-05-10 08:30:00

PHP-FPMnginx

2012-07-25 22:15:00

Nginxlua

2012-09-18 13:24:10

互联网创业项目
点赞
收藏

51CTO技术栈公众号