http://blog.csdn.net/marising/article/details/3932938

1.Nginx

1.1.安装

  1. Nginx 的中文维基 http://wiki.codemongers.com/NginxChs 下载 Nginx 0.6.26(开发版)(请下载最新版本)
  2. tar zxvf nginx-0.6.26.tar.gz
  3. ./configure,注意了类似checking for *** ... not found项,可能是依赖包没有,则需要安装依赖包
  4. 缺少PCRE,sudo apt-get install pcre安装。或者去:http://www.pcre.org/
  5. 如果缺少OpenSSL,sudo apt-get install libssl-dev,或者去:http://www.openssl.org
  6. 如果缺少zlib,可以apt-get install zlib1g,或者http://www.zlib.net/
  7. 配置请参考:http://wiki.codemongers.com/NginxChsInstall 可以选择安装模块
  8. make & make install
  9. 默认安装在/usr/local/nginx下

1.2.管理

  1. 执行选项
    -c </path/to/config> 为 Nginx 指定一个配置文件,来代替缺省的。
    -t 不运行,而仅仅测试配置文件。nginx 将检查配置文件的语法的正确性,并尝试打开配置文件中所引用到的文件。
    -v 显示 nginx 的版本。
    -V 显示 nginx 的版本,编译器版本和配置参数。
  2. 检查配置文件
    $ sudo nginx -t
    2008/03/12 19:15:11 info 12384#0: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
    2008/03/12 19:15:11 info 12384#0: the configuration file /usr/local/nginx/conf/nginx.conf was tested successfully
  3. 启动
    /usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
  4. 查看nginx主进程号
    $ ps -ef | grep "nginx: master process"
    | grep -v "grep"
    | awk -F ' ' '{print $2}
    26010
  5. 重新加载配置文件
    $sudo kill -HUP 26010

    通过系统的信号控制 Nginx
    可以使用信号系统来控制主进程。默认,nginx 将其主进程的 pid 写入到 /usr/local/nginx/logs/nginx.pid 文件中。通过传递参数给 ./configure 或使用 pid 指令,来改变该文件的位置。
    主进程可以处理以下的信号:

    命令 说明 备注
    TERM, INT 快速关闭  
    QUIT 从容关闭  
    HUP 重载配置 用新的配置开始新的工作进程    从容关闭旧的工作进程
    USR1 重新打开日志文件  
    USR2 平滑升级可执行程序  
    WINCH 从容关闭工作进程  
  6. 默认目录
    主目录:/usr/local/nginx/
    配置目录:/usr/local/nginx/conf/
    root目录:/usr/local/nginx/html/
    可执行文件路径:/usr/local/nginx/sbin/

2.FastCGI

2.1.安装lighttpd的spawn-fastcgi

下载http://www.lighttpd.net/download/lighttpd-1.4.19.tar.gz

./configure
make
cp ./src/spawn-fcgi /usr/local/nginx/sbin/

2.2.安装fastcgi库

下载http://www.fastcgi.com/dist/fcgi.tar.gz

./configure
make
make install

2.3.Hello world

#include <iostream>
#include <fcgi_stdio.h>
using namespace std;
int main()
{
/* Initialization Code */
int count = 0; /* Start of response loop */
while (FCGI_Accept() >= 0)
{
//* body of response loop /*/
printf("Content-type: text/html/r/n"
"/r/n"
""
"FastCGI Hello/! (C, fcgi_stdio library)"
"Request number %d running on host %s "
"Process ID: %d/n",
/++count,
getenv("SERVER_NAME"), getpid());
} /* End of response loop */
return 0; }

编译后为FastCGISameple

2.4.启动Spawn-cgi

/usr/local/nginx/sbin/spawn-fcgi -a 127.0.0.1 -p 9000 -C 25 -u www -f /usr/local/nginx/fcgi/FactCGISample

2.5.修改Nginx配置文件

vi /usr/local/nginx/conf/nginx.conf

location ~ /.cgi$

{    
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.cgi;
fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
      include fastcgi_params;
}

别忘了,重新加载配置文件

$sudo kill -HUP 26010

打开浏览器,输入http://localhost/1.cgi ,就显示

FastCGI Hello! (C, fcgi_stdio library)Request number 1 running on host localhost Process

 ID: 25473

3.webbench压力测试工具

下载:http://home.tiscali.cz:8080/~cz210552/distfiles/webbench-1.5.tar.gz

安装:

tar zxvf webbench-1.5.tar.gz
cd webbench-1.5 make && make install

使用:

webbench -c 500 -t 30 http://127.0.0.1/test.jpg

500是并发连接数,30是时间单位是秒

用ab测试的结果,在我的虚拟机上,看起来性能很不错

(Apache Bench是Apache自带的工具包)

ab -n 10000 -c 100 http://127.0.0.1/1.cgi
This is ApacheBench, Version 2.3 <$Revision: 655654 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/

Benchmarking 127.0.0.1 (be patient)
Completed 1000 requests
Completed 2000 requests
Completed 3000 requests
Completed 4000 requests
Completed 5000 requests
Completed 6000 requests
Completed 7000 requests
Completed 8000 requests
Completed 9000 requests
Completed 10000 requests
Finished 10000 requests

Server Software:        nginx/0.7.38
Server Hostname:        127.0.0.1
Server Port:            80

Document Path:          /1.cgi
Document Length:        143 bytes

Concurrency Level:      100
Time taken for tests:   3.982 seconds
Complete requests:      10000
Failed requests:        8399
   (Connect: 0, Receive: 0, Length: 8399, Exceptions: 0)
Write errors:           0
Total transferred:      2658399 bytes
HTML transferred:       1438399 bytes
Requests per second:    2511.06 [#/sec] (mean)
Time per request:       39.824 [ms] (mean)
Time per request:       0.398 [ms] (mean, across all concurrent requests)
Transfer rate:          651.89 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        0    1   4.6      0      51
Processing:    22   39   6.8     36      93
Waiting:        4   39   6.8     36      93
Total:         24   39   8.2     36      97

Percentage of the requests served within a certain time (ms)
  50%     36
  66%     39
  75%     41
  80%     42
  90%     48
  95%     54
  98%     70
  99%     84
 100%     97 (longest request)

4.Nginx模块

模块列表
http://wiki.codemongers.com/NginxModules

FastCGI模块源码:nginx/src/http/modules/ngx_http_fastcgi_module.c

nginx+c+cgi开发的更多相关文章

  1. 搭建windows环境下(nginx+mysql+php)开发环境

    搭建windows环境下(nginx+mysql+php)开发环境   1. 所需准备应用程序包        1.1 nginx 程序包nginx-1.0.4.zip或其他版本(下载地址: http ...

  2. Win7搭建nginx+php+mysql开发环境以及websocket聊天实例测试

    Win7搭建nginx+php+mysql开发环境以及websocket聊天实例测试一.下载相关安装包 1.下载nginx最新版本(nginx1.3.13版之后才支持websocket协议) 下载地址 ...

  3. Nginx+Lua(OpenResty)开发高性能Web应用

    使用Nginx+Lua(OpenResty)开发高性能Web应用 博客分类: 跟我学Nginx+Lua开发 架构 ngx_luaopenresty 在互联网公司,Nginx可以说是标配组件,但是主要场 ...

  4. Nginx Http模块开发

    关于Nginx Http模块开发的文章非常少,只有Emiler的那篇关于Http模块的文章,但是那篇文章里面,并没有说到事件型的模块如何进行开发.而且文章里面提到的内容实在是让人有点意犹未尽.因此,对 ...

  5. Nginx与前端开发

    Nginx与Node.js "Nginx是一款轻量级的HTTP服务器,采用事件驱动的异步非阻塞处理方式框架,这让其具有极好的IO性能,时常用于服务端的反向代理和负载均衡." 作为前 ...

  6. nginx+uwsgi+django开发环境搭建

    Nginx+uWSGI+Djangoi开发环境搭建 Django简介,环境搭建 uWSGI简介,安装与配置 Nginx安装与配置 Nginx+uWSGI+Django原理解析 1.django简介,环 ...

  7. 安装Nginx+Lua+OpenResty开发环境配置全过程实例

    安装Nginx+Lua+OpenResty开发环境配置全过程实例 OpenResty由Nginx核心加很多第三方模块组成,默认集成了Lua开发环境,使得Nginx可以作为一个Web Server使用. ...

  8. nginx http模块开发入门

    导语 本文对nginx http模块开发需要掌握的一些关键点进行了提炼,同时以开发一个简单的日志模块进行讲解,让nginx的初学者也能看完之后做到心里有谱.本文只是一个用作入门的概述. 目录 背景 主 ...

  9. CGI开发-(转自 jemofh159)

    随着Internet技术的兴起,在嵌入式设备的管理与交互中,基于Web方式的应用成为目前的主流,这种程序结构也就是大家非常熟悉的B/S结构,即在嵌入式设备上运行一个支持脚本或CGI功能的Web服务器, ...

随机推荐

  1. template模版与Underscore.js

    template模版与Underscore.js 在项目中经常使用的模版是Underscore这个js框架的实用功能. 在html里面设定模板,然后js绑定数据,这样能避免在js中出现非常多的html ...

  2. DIV使用tabindex获得事件详解 移动div

    添加 tabindex='-1' 属性: 默认:获取不到焦点事件(blur) 1 <div class="wl-product" id="wl-product&qu ...

  3. Dapper使用

    公司的项目使用了Dapper做数据库连接处理,感觉不错,自己研究一下怎么用. 在网上找了找资料对Dapper都比较推崇.主要是两个方面,一个是连接速度很快,一个是代码开源且简单,只有一个SqlMapp ...

  4. JAVA-数据库连接【转】

    SqlServer.Oracle.MySQL的连接,除了地址和驱动包不同,其他都一样的. 1 public String urlString="jdbc:sqlserver://localh ...

  5. 动态链接库dll键盘钩子后台记录代码示例

    //.header #ifndef _DLLHOOK_H_ #define _DLLHOOK_H_ #include <windows.h> #define DLL_EXPORT_FUN ...

  6. 向MySql中插入中文时出现乱码

    这个因为字符集编码问题.在连接字符串中加上CharSet=gbk

  7. Linux - gcc和g++的区别

    一般linux系统都自带了gcc编译器的,你可以用你的安装光盘去安装,如果你是觉得自带的gcc版本太低了,可以去gcc的官方网站可以下载到,编译需要很长的时间,如果你只编译C或者C++可以只下载gcc ...

  8. C++-模板的声明和实现为何要放在头文件中

    源: http://blog.csdn.net/lqk1985/archive/2008/10/24/3136364.aspx 如何组织编写模板程序 发表日期: 1/21/2003 12:28:58 ...

  9. bzoj 1185 旋转卡壳 最小矩形覆盖

    题目大意 就是求一个最小矩形覆盖,逆时针输出其上面的点 这里可以看出,那个最小的矩形覆盖必然有一条边经过其中凸包上的两个点,另外三条边必然至少经过其中一个点,而这样的每一个点逆时针走一遍都满足单调性 ...

  10. Linux摄像头驱动学习之:(一)V4L2_框架分析

    这段时间开始搞安卓camera底层驱动了,把以前的的Linux视频驱动回顾一下,本篇主要概述一下vfl2(video for linux 2). 一. V4L2框架: video for linux ...