1.Nginx
1.1.安装
Nginx 的中文维基 http://wiki.codemongers.com/NginxChs 下载 Nginx 0.6.26(开发版)(请下载最新版本)
tar zxvf nginx-0.6.26.tar.gz
./configure,注意了类似checking for *** ... not found项,可能是依赖包没有,则需要安装依赖包
缺少PCRE,sudo apt-get install pcre安装。或者去:http://www.pcre.org/
如果缺少OpenSSL,sudo apt-get install libssl-dev,或者去:http://www.openssl.org
如果缺少zlib,可以apt-get install zlib1g,或者http://www.zlib.net/
配置请参考:http://wiki.codemongers.com/NginxChsInstall 可以选择安装模块
make & make install
默认安装在/usr/local/nginx下
1.2.管理
执行选项
-c </path/to/config> 为 Nginx 指定一个配置文件,来代替缺省的。
-t 不运行,而仅仅测试配置文件。nginx 将检查配置文件的语法的正确性,并尝试打开配置文件中所引用到的文件。
-v 显示 nginx 的版本。
-V 显示 nginx 的版本,编译器版本和配置参数。
检查配置文件
$ 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
启动
/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
查看nginx主进程号
$ ps -ef | grep "nginx: master process"

| grep -v "grep"

| awk -F ' ' '{print $2}

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

命令 说明 备注
TERM, INT 快速关闭
QUIT 从容关闭
HUP 重载配置 用新的配置开始新的工作进程 从容关闭旧的工作进程
USR1 重新打开日志文件
USR2 平滑升级可执行程序
WINCH 从容关闭工作进程
默认目录
主目录:/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

转载于:https://blog.51cto.com/flandycheng/858946

nginx+fastcgi+c/c++搭建高性能Web框架相关推荐

  1. Nginx + FastCGI 程序(C/C++) 搭建高性能web service的Demo及部署发布

    1.介绍     Nginx - 高性能web server,这个不用多说了,大家都知道.     FastCGI程序 - 常驻型CGI程序,它是语言无关的.可伸缩架构的CGI开放扩展,其主要行为是将 ...

  2. 【入门篇】Nginx + FastCGI 程序(C/C++) 搭建高性能web service的Demo及部署发布

    http://blog.csdn.net/allenlinrui/article/details/19419721 分类: C/C++2014-02-18 17:58 3875人阅读 评论(0) 收藏 ...

  3. Centos 搭建高性能WEB服务 Nginx+PHP+MYSQL+Discuz论坛

    Centos 搭建高性能WEB服务 Nginx+PHP+MYSQL+Discuz论坛 Nginx 是由 Igor Sysoev 为俄罗斯访问量第二的 Rambler.ru 站点开发的,它已经在该站点运 ...

  4. 分享关于搭建高性能WEB服务器的一篇文章

    这篇文章主要介绍了Centos5.4+Nginx-0.8.50+UWSGI-0.9.6.2+Django-1.2.3搭建高性能WEB服务器的相关资料,需要的朋友可以参考下(http://m.0813s ...

  5. 高性能Web框架FastAPI v0.62.0

    介绍: FastAPI是一个高性能Web框架,用于构建API. 主要特性: 1.快速:非常高的性能,与NodeJS和Go相当 2.快速编码:将功能开发速度提高约200%至300% 3.更少的错误:减少 ...

  6. 实战:Nginx + FastCGI 程序(C/C++) 搭建高性能web server

    1.介绍 Nginx - 高性能web server,这个不用多说了,大家都知道. FastCGI程序 - 常驻型CGI程序,它是语言无关的.可伸缩架构的CGI开放扩展,其主要行为是将CGI解释器进程 ...

  7. Nginx 0.8.x + PHP 5.2.13(FastCGI)搭建高性能Web服务器

    Nginx ("engine x") 是一个高性能的 HTTP 和反向代理服务器,也是一个 IMAP/POP3/SMTP 代理服务器. Nginx 是由 Igor Sysoev 为 ...

  8. nginx怎么控制socket链接转发到某台服务器_Nginx + FastCGI 程序(C/C++) 搭建高性能web service...

    1.介绍 Nginx - 高性能web server,这个不用多说了,大家都知道. FastCGI程序 - 常驻型CGI程序,它是语言无关的.可伸缩架构的CGI开放扩展,其主要行为是将CGI解释器进程 ...

  9. Nginx + PHP 搭建高性能web服务器

    写在前面: 1. Issue: *** 'libmcrypt-config --version' returned 2.4.0, but LIBMCRYPT (2.5.8) *** was found ...

最新文章

  1. Android点赞音效播放
  2. 昨天电脑问题 补昨日8-3复习内容 异常与文件操作
  3. 《从零开始学习ASP.NET MVC 1.0》-开天辟地入门篇
  4. 上周热点回顾(6.17-6.23)
  5. Spring MVC-视图解析器(View Resolverr)-内部资源视图解析器(Internal Resource View Resolver)示例(转载实践)...
  6. 【Pytorch神经网络理论篇】 33 基于图片内容处理的机器视觉:目标检测+图片分割+非极大值抑制+Mask R-CNN模型
  7. java三目运算符简化代码_如何使用传播运算符简化代码
  8. java1234 webservice 第4 课 拦截器
  9. 关于发邮件报错535 Error:authentication failed解决方法
  10. 凸优化第五章对偶 5.2Lagrange对偶问题
  11. c语言 json解析器,撸一个JSON解析器
  12. pytorch源码解析1——torch.optim:优化算法接口详解
  13. 搭建STM32开发环境
  14. android 平板 不支持apk,平板电脑上怎么无法打开apk文件
  15. pinpoint全链路监控安装部署(支持dubbo)
  16. WINDOWS远程连接显示“请稍后”
  17. 要不是这些沙雕插件,我早就被公司开除了。
  18. 云呐|固定资产条码管理系统的应用
  19. 【app开发学习】APP开发的标准流程
  20. 第六届 虚拟漫游 题目

热门文章

  1. 洛谷 P4284 [SHOI2014]概率充电器 解题报告
  2. 谈谈环保问题之四-做环保的程序员
  3. 【转】iOS-Core-Animation-Advanced-Techniques(六)
  4. 演义群侠传(七)【GC垃圾回收】
  5. JAVA数字处理类使用2
  6. 代码生成工具CodeSmith中SchemaExplorer类API文档[转]
  7. 总结一下F#中运算符的定义规则
  8. r语言提取列名_R语言基础(2)向量|矩阵|数组|数据框|数据IO|实用函数
  9. STM32 基础系列教程 43 – SRAM
  10. 【DIY】可能是最实用最便宜的 arduino 温湿度计方案,200615整合家用声控温湿度计完整方案...