参考: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. 43. Multiply Strings

    /** * @param {string} num1 * @param {string} num2 * @return {string} */ var multiply = function(num1 ...

  2. .技术参数图用pillow自动处理

    python 2.7 pillow 安装python2.7.10(自带pip),修改豆瓣源,下载pillow

  3. js判断浏览器类型

    使用navigator.userAgent和来判断 PC端: <script type="text/javascript">var ua=navigator.userA ...

  4. thusc2016游记&&滚粗记&&酱油记

    #include <cstdio> using namespace std; int main(){ puts("转载请注明出处:http://www.cnblogs.com/w ...

  5. POJ 1966 Cable TV Network

    Cable TV Network Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 4702   Accepted: 2173 ...

  6. 【BZOJ-4726】Sabota? 树形DP

    4726: [POI2017]Sabota? Time Limit: 20 Sec  Memory Limit: 128 MBSec  Special JudgeSubmit: 128  Solved ...

  7. apache.commons.compress 压缩,解压

    最近在一个前辈的指引下,开始研究apache.commons.都是网上找的,而且不会中文乱码,而且还可以在压缩包里面加一层文件夹 package my.test; import java.io.Buf ...

  8. Non-blocking read on a subprocess.PIPE in python

    import sys from subprocess import PIPE, Popen from threading import Thread try: from Queue import Qu ...

  9. webView和js交互

    与 js 交互 OC 调用 JS // 执行 js - (void)webViewDidFinishLoad:(UIWebView *)webView { NSString *title = [web ...

  10. Linux中文显示乱码?如何设置centos显示中文

    Linux中文显示乱码?如何设置centos显示中文 怎么设置Linux系统中文语言,这是很多小伙伴在开始使用Linux的时候,都会遇到一个问题,就是终端输入命令回显的时候中文显示乱码.出现这个情况一 ...