参考: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. 从点云到网格(二)VRIP介绍

    VRIP(Volumetric Range Image Processing),顾名思义,是从深度图重建网格的一种方法.VRIP是Brian Curless和Marc Levoy在1996年提出来的方 ...

  2. 启动 Eclipse 弹出“Failed to load the JNI shared library jvm.dll”错误的解决方法

    原因1:给定目录下jvm.dll不存在. 对策:(1)重新安装jre或者jdk并配置好环境变量.(2)copy一个jvm.dll放在该目录下. 原因2:eclipse的版本与jre或者jdk版本不一致 ...

  3. 练习JavaScript实现过滤特殊字符

    for循环遍历特殊字符和用户输入字符,然后做比较,返回结果. <script type="text/javascript"> var name = prompt(&qu ...

  4. Nginx 1.10.1 编译、配置文档(支持http_v2,TLSv1.2,openssl v1.0.2)

    1.安装常用工具及基础包: [root@localhost /]# yum -y install wget git vim make gcc gcc-c++ openssl-devel [root@l ...

  5. OVGap iOS与Javascript交互(H5与原生APP交互)

    源代码:https://github.com/windshg/OVGap OVGap:一个轻量级的类库,能够让iOS应用和远程网页的 Javascript 代码进行通信,也就是说,远程的 Javasc ...

  6. HTML5学习总结-番外03 Angular Ionic

    一 Angular Angular使用了MVVC设计模式,MVVC在概念上是真正将页面与数据逻辑分离的模式,它把数据绑定工作放到一个JS里去实现,而这个JS文件的主要功能是完成数据的绑定,即把mode ...

  7. iOS - 消息转发处理

    详细运行时基础 NSInvocation介绍 NSHipster-Swizzling Objective-C Method相关方法分析 Type Encodings Objc是OOP,所以有多态. 当 ...

  8. Sonar安装配置

    https://www.sonarqube.org/downloads/ 下载sonar.当前版本为6.2 解压压缩包,进行配置: 修改sonarqube-6.2\conf\sonar.propert ...

  9. Swift -Login(MVC 纯代码)

    p.p1 { margin: 0.0px 0.0px 0.0px 0.0px; font: 24.0px Menlo; color: #000000 } span.s1 { } span.s2 { c ...

  10. eclipse自动补全的设置

    eclipse自动补全的设置   如果你用过Visual Studio的自动补全功能后,再来用eclipse的自动补全功能,相信大家会有些许失望. 但是eclipse其实是非常强大的,eclipse的 ...