nginx+fastcgi+c/cpp
参考: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的更多相关文章
- Nginx + CGI/FastCGI + C/Cpp
接着上篇<Nginx安装与使用>,本篇介绍CGI/FASTCGI的原理.及如何使用C/C++编写简单的CGI/FastCGI,最后将CGI/FASTCGI部署到nginx.内容大纲如下: ...
- 【转】Nginx + CGI/FastCGI + C/Cpp
接着上篇<Nginx安装与使用>,本篇介绍CGI/FASTCGI的原理.及如何使用C/C++编写简单的CGI/FastCGI,最后将CGI/FASTCGI部署到nginx.内容大纲如下: ...
- Nginx + FastCGI 程序(C/C++) 搭建高性能web service的Demo及部署发布
FastCGI编程包括四部分:初始化编码.接收请求循环.响应内容.响应结束循环. FCGX_Request request; FCGX_Init(); ); FCGX_InitRequest(& ...
- 【入门篇】Nginx + FastCGI 程序(C/C++) 搭建高性能web service的Demo及部署发布
http://blog.csdn.net/allenlinrui/article/details/19419721 1.介绍 Nginx - 高性能web server,这个不用多说了,大家都 ...
- Nginx+FastCGI运行原理
Nginx不支持对外部程序的直接调用或者解析,所有的外部程序(包括PHP)必须通过FastCGI接口来调用.FastCGI接口在Linux下是socket(这个socket可以是文件socket,也可 ...
- 记录一次自己对nginx+fastcgi(fpm)+mysql压力测试结果
nginx + fastcgi(fpm) 压力测试: CentOS release 5.9 16核12G内存 静态页面: 并发1000,压测200秒,测试结果: 系统最大负载5.47 成功响应: 25 ...
- nginx fastcgi php-fpm的关系梳理
CGI(Common Gateway Interface)CGI全称是“公共网关接口”(Common Gateway Interface),HTTP服务器与你的或其它机器上的程序进行“交谈”的一种工具 ...
- windows下nginx+fastcgi不能使用file_get_contents/curl/fopen的原因
这两天一直在搞windows下nginx+fastcgi的file_get_contents请求.我想,很多同学都遇到当file_get_contents请求外网的http/https的php文件时毫 ...
- [转] nginx+FastCGI+c++
from: http://www.cnblogs.com/xiaouisme/archive/2012/08/01/2618398.html 一 安装 目的:不需支持php等.就html就行了.步骤: ...
随机推荐
- iOS 中block中使用了外部变量的分析
例子1: ; void (^blk)(void) = ^(){ printf("in block %d[%p]\n", val, &val); //in block 10[ ...
- centos 安装lnmp
1:查看环境 cat /etc/redhat-release 2:关闭防火墙 chkconfig iptables off 3:配置CentOS 6.0 第三方yum源(CentOS默认的标准源里没有 ...
- SpringCloud: 服务发现
p.p1 { margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px "Helvetica Neue"; color: #e4af0a } sp ...
- Android 天猫apk聊天数据库解密
1.使用Android 天猫apk 进行聊天会产生tmallWangXinDB的数据库.2.用sqlite3 工具打开提示加密或者错误.3.需要对该数据库进行解密. 解密流程:1.反编译apk,dex ...
- windows bat批处理语法简析
第一节先介绍windows批处理.这个起源于跟旁边同事学习在windows用命令行办公,渐渐地有些批处理功能就需要了,于是专门抽出了几天学习了一下.我认为文档最重要的功能是为了备忘,择取了很多文档的例 ...
- Debian8 从本地源安装软件
假如你从Debian官网下载了三个DVD镜像,那么就可以设置从本地源来安装软件,例如这里我从官网下载了 debian-8.6.0-amd64-DVD-1.iso,debian-8.6.0-amd64- ...
- macOS Sierra U盘USB启动安装盘
http://www.iplaysoft.com/macos-usb-install-drive.html 文章里提供了一个软件可以自动化操作,但是试了下,不行,试了两三次还是不行,只有参照文章中的第 ...
- ADB
adb logcat 命令详解 log过滤 http://blog.csdn.net/liao277218962/article/details/50129009 如何使用 adb logcat 查看 ...
- 对路径的访问被拒绝,解决之后又报-未在本地计算机上注册“Microsoft.Jet.OLEDB.4.0”提供程序。
服务器环境:Server 2008 64位系统 问题:在导入Excel题录表时报错,1对路径的访问被拒绝,2未在本地计算机上注册“Microsoft.Jet.OLEDB.4.0”提供程序. 解决方案 ...
- thinkphp疑难解决4
关于文件上传所涉及到的php.ini 中的一些配置: (以当前要设置的关键字开头...) 是每个上传文件所允许的大小, 默认的 upload_max_filesize = 2M, 如果超过了2M,_P ...