参考:http://github.tiankonguse.com/blog/2015/01/19/cgi-nginx-three/

跟着做了一遍,然后根据记忆写的,不清楚有没错漏步骤,希望多多评论多多交流。。。

搭建环境

注意发现碰钉可以看看相应程序内的README

安装:nginx、spawn-fcgi、fastcgi、fcgiwrap

nginx

sudo apt-get install nginx-full

fastcgi

安装fastcgi的时候报EOF错误可以在include/fcgio.h中包含头文件cstdio

wget http://www.fastcgi.com/dist/fcgi.tar.gz
tar -zxvf fcgi.tar.gz
./configure
make
sudo make install

spawn-fcgi

git clone https://github.com/lighttpd/spawn-fcgi.git
sudo apt-get install autoconf
autoreconf -i
./autogen.sh
./configure
make
sudo make install

fcgiwrap

git clone https://github.com/gnosek/fcgiwrap.git
autoreconf -i
./configure
make
sudo make install

配置环境

配置nginx

vim /etc/nginx/sites-enabled/default

整个文件改成这样

server {

    listen  ;
server_name nextbin.com; location / {
root /home/zebin/nginx/htdoc/;
index index.html index.htm;
try_files $uri $uri/ =;
} location ~ ^/cgi-bin/.*$ {
#cgi path: /home/zebin/nginx/cgi-bin/
root /home/zebin/nginx/;
fastcgi_pass 127.0.0.1:;
#configure path: /etc/nginx/fastcgi.conf
#include fastcgi.conf;
include fastcgi_params;
} }

配置hosts

vim /etc/hosts

追加

127.0.0.1 nextbin.com

配置库文件链接

sudo ln -s /usr/local/lib/libfcgi.so.0.0. /usr/local/lib/libfcgi.so.
sudo ln -s /usr/local/lib/libfcgi.so.0.0. /usr/lib/libfcgi.so.0
sudo mkdir /usr/lib64
sudo ln -s /usr/local/lib/libfcgi.so.0.0. /usr/lib64/libfcgi.so.

测试cgi

编写cgi程序编译后将可执行程序放在相应目录(如/home/zebin/nginx/cgi-bin/demo)

#include "fcgi_stdio.h"
#include <stdlib.h> int main(int argc, char* argv[]){
int count = ;
while (FCGI_Accept() >= ){
printf("Content-type: text/html\r\n"
"\r\n"
"<title>FastCGI Hello!</title>"
"<h1>FastCGI Hello!</h1>"
"Request number %d running on host <i>%s</i>\n",
++count, getenv("SERVER_NAME"));
}
return ;
}

demo.cpp

编译:g++ demo.cpp -lfcgi -o demo

加载fcgi-application

spawn-fcgi -p 9000 -C 10  -f  /usr/local/sbin/fcgiwrap

浏览器访问 nextbin.com/cgi-bin/demo 都成功

=========小结=========

一些用得上的命令

ps -aux | grep cgi
nginx -t
ln --help

折腾了一天终于搭建好了。之前只试过LNMP。

1. 还没用上数据库,有待补充

2. 对spawn-fcgi、fcgiwrap、fastcgi的关系不清晰,有待理解

3. 对信息传输交互没接触,有待构建

nginx+fastcgi+c/cpp的更多相关文章

  1. Nginx + CGI/FastCGI + C/Cpp

    接着上篇<Nginx安装与使用>,本篇介绍CGI/FASTCGI的原理.及如何使用C/C++编写简单的CGI/FastCGI,最后将CGI/FASTCGI部署到nginx.内容大纲如下: ...

  2. 【转】Nginx + CGI/FastCGI + C/Cpp

    接着上篇<Nginx安装与使用>,本篇介绍CGI/FASTCGI的原理.及如何使用C/C++编写简单的CGI/FastCGI,最后将CGI/FASTCGI部署到nginx.内容大纲如下: ...

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

       FastCGI编程包括四部分:初始化编码.接收请求循环.响应内容.响应结束循环. FCGX_Request request; FCGX_Init(); ); FCGX_InitRequest(& ...

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

    http://blog.csdn.net/allenlinrui/article/details/19419721 1.介绍     Nginx - 高性能web server,这个不用多说了,大家都 ...

  5. Nginx+FastCGI运行原理

    Nginx不支持对外部程序的直接调用或者解析,所有的外部程序(包括PHP)必须通过FastCGI接口来调用.FastCGI接口在Linux下是socket(这个socket可以是文件socket,也可 ...

  6. 记录一次自己对nginx+fastcgi(fpm)+mysql压力测试结果

    nginx + fastcgi(fpm) 压力测试: CentOS release 5.9 16核12G内存 静态页面: 并发1000,压测200秒,测试结果: 系统最大负载5.47 成功响应: 25 ...

  7. nginx fastcgi php-fpm的关系梳理

    CGI(Common Gateway Interface)CGI全称是“公共网关接口”(Common Gateway Interface),HTTP服务器与你的或其它机器上的程序进行“交谈”的一种工具 ...

  8. windows下nginx+fastcgi不能使用file_get_contents/curl/fopen的原因

    这两天一直在搞windows下nginx+fastcgi的file_get_contents请求.我想,很多同学都遇到当file_get_contents请求外网的http/https的php文件时毫 ...

  9. [转] nginx+FastCGI+c++

    from: http://www.cnblogs.com/xiaouisme/archive/2012/08/01/2618398.html 一 安装 目的:不需支持php等.就html就行了.步骤: ...

随机推荐

  1. Angular select 绑定复杂类型 设置默认项

    <select ng-model="selectedTask" ng-options="s.name for s in TaskList">< ...

  2. Android系统全貌 (转)

    转自Gityuan的Android开篇,对自我学习作进一步整理. Android系统以Linux内核作为基底,上层采用Native层和Java层.系统分为内核空间和用户空间,并通过系统调用(Sysca ...

  3. COGS2531. [HZOI 2016]函数的美 打表+欧拉函数

    题目:http://cogs.pw/cogs/problem/problem.php?pid=2533 这道题考察打表观察规律. 发现对f的定义实际是递归式的 f(n,k) = f(0,f(n-1,k ...

  4. 网站引入了css样式文件能访问,就是没有效果

    今天后端的同事遇到这么个问题,引入了外部css文件也能访问,就是页面上没有效果. 大概是下面这个样子: css引入如下: 我非常的纳闷,说真的我还没遇到过这种情况,UI是可以运行的,一点事都没有... ...

  5. 构造函数忘记new? 看这里看这里

    方法一:自调用构造函数 function Person(name){ if( !(this instanceof Person)){//一定要放在开头.检查this是否为构造函数的一个实例 retur ...

  6. js

    1.判断是否为空 if (typeof(a)!="undefined") 2. pop()移除数组最后一个元素 var arr = [];   $('#tableid tr').f ...

  7. applicationContext.xml

    <bean id="dataSource" parent="parentDataSource"> <property name="u ...

  8. JEECG 社区开源项目下载(总览)

    反馈问题板块:http://www.jeecg.org/forum.php?mod=forumdisplay&fid=153 资源1: JEECG 微云快速开发平台( JEECG 3.6.5  ...

  9. Fedora20-64bit cross-compiling arm-linux-gcc

    0按照友善之臂的手册建立交叉编译环境时,添加用户变量,最好是去更改 profile 文件 因为 profile 是所有用户都可以使用的,类似于 windows 中的系统变量 而 .bashrc 只有该 ...

  10. Standard C 语言标准函数库介绍

    全面巩固所知所学,往精通方向迈进! Standard C 语言标准函数库速查 (Cheat Sheet) from:http://ganquan.info/standard-c/function/ C ...