注:该博文转自 How to run fastcgi and nginx on windows,由于网上FastCGI相关的资料较少,故转载存档。原文章创作于2013年,原文中部分链接资料已经失效,并且有少量的显示错误,现已更正,方便之后查阅。如有侵权,请联系删除。
Step by step guide how to configure nginx on windows….

Download and installation

Download nginx package from nginx site. Unpack it and installation is done.

Example of fast-cgi application

No create and complie fast-cgi application. (How to compile fast-cgi on windows)

#include "fcgi_stdio.h"
#include <stdlib.h>void main(void)
{int count = 0;while(FCGI_Accept() &gt;= 0)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"));
}

How to connect fast-cgi with web-server

There are two ways. When web-server supports fast-cgi you will be able to connect fast-cgi directly with web-server via configuration files. In all other cases fast-cgi offers cgi-fcgi executable as bridge between webserver and your app. More info about both these approaches you can find here http://www.fastcgi.com/devkit/doc/fcgi-devel-kit.htm#S4.(该链接已经失效)

Working way how to get fastcgi apps working

None of two ways described in previous article and in official documentation works for me on windows. I wasn’t able to get cgi-fcgi or spawn-fcgi running. First mentioned crashed everytime app tries to initialize STD_OUT, the second one isn’t possible to compile it because of missing unistd.h header.

Fortunately there is one more way. FCGI library offers one more way how to utilize FCGI mechanism. It’s necessary add two more lines to example above and everything works perfectly.

#include "fcgi_stdio.h"
#include &lt;stdlib.h&gt;void main(void)
{//initialize library &amp; open listening socket at port 9345FCGX_Init();FCGX_OpenSocket(":9345",500);//rest is the same as in example abovewhile(FCGI_Accept() >= 0) ...
}

After this change application initialize listening port and waits for incoming data. All you need to do is directly execute the app.

Configure nginx to connect with fast-cgi

This step compared to previous ones is pretty easy. You need to tell nginx server what and where to pass. Open file nginx.conf and add following statement:

http {server {location / {fastcgi_pass 127.0.0.1:9345;}}
}

fastcgi_pass statement forward all requests to localhost:9345 address. Now when you start your nginx server, everything should work as expected.

Troubleshooting

bind() to 0.0.0.0:80 failed
This error is caused by another application which uses port 80. In my case it was Skype which automatically uses port 80.

nginx: [emerg] bind() to 0.0.0.0:80 failed (10013: An attempt was made to access a socket in a way forbidden by its access permissions)

External links

  • http://chriswu.me/blog/writing-hello-world-in-fcgi-with-c-plus-plus/
  • https://code.google.com/p/heeds/wiki/HEEDS_FastCGI_nginx
  • http://stackoverflow.com/questions/1945293/how-can-fastcgi-applications-be-started-manually-on-windows

FastCGI - How to run fastcgi and nginx on windows相关推荐

  1. php fastcgi进程启动,php fastcgi 启动脚本

    php fastcgi 启动脚本 以FASTCGI模式启动PHP,通过此脚本,可以以守护进程模式启动PHP的FASTCGI模式. 启动脚本 /home/hliang/fcgi-php: [cc lan ...

  2. php fastcgi,配置apache以fastcgi运行php

    apache默认是用自带的mod_php模块运行php,现在我们介绍使用fastcgi来执行php脚本.先说下fastcgi的优点: Fastcgi的优点: 从稳定性上看, fastcgi是以独立的进 ...

  3. 【转载】nginx for windows: 让nginx以服务的方式运行

    nginx for windows: 让nginx以服务的方式运行 在windows下安装了nginx, 郁闷是发现它没有以服务方式运行, 也就是说当用户注销后,程序 会终止.因此需要将nginx作为 ...

  4. 为 Nginx 创建 windows 服务自启动

    1.下载最新版的 Windows Service Wrapper 程序 下载地址:http://download.java.net/maven/2/com/sun/winsw/winsw/1.9/ 2 ...

  5. Nginx For Windows 路由配置

    Nginx For Windows 路由配置 一.路由配置说明 二.需求说明 三.配置文件 一.路由配置说明 使用Nginx进行路由配置. 使用过 SpringCloud 网关的同学都知道,网关可以使 ...

  6. Nginx For Windows Socket 端口转发

    Nginx For Windows Socket 端口转发 一.需求说明 二.配置文件 一.需求说明 使用Nginx进行端口转发 Socket 端口通信. 监控本地服务器的 3001 端口,转发到 1 ...

  7. Nginx For Windows HTTP转发和负载

    Nginx For Windows HTTP转发和负载 一.需求说明 二.配置文件 一.需求说明 使用Nginx进行端口转发,并且负载到两台服务器的服务上. 监控本地服务器的 9099 端口,转发并负 ...

  8. Nginx For Windows 关于 worker_connections 不生效问题

    ○.结论 Nginx For Windows 建议使用 http://nginx-win.ecsds.eu/ 下载 nginx 1.17.0.1 Crow 一.起因 项目中有一个 API 服务,对客户 ...

  9. Nginx在windows下使用为什么死掉

    这个现象很奇怪,Nginx部署在windows服务器上之后,大概八九个小时之后就不行了 后来我修改了下最大链接数为200多,好像坚持了不到4个小时,从访问日志上可以看到, 死掉之后,nginx完全失去 ...

最新文章

  1. Java--------------Mysql中时间按要求查询
  2. 梯度下降,损失函数-讲的很好
  3. 使用Apache Flume抓取数据(1)
  4. C#自定义字符串压缩和解压缩源码库
  5. android 5.1 壁纸路径,RTFSC – Android5.1 壁纸设置流程简析 – RustFisher
  6. ie8 html 编辑器 为word,ie8生成word
  7. 04_Spring中使用Quartz
  8. Hadoop本地运行模式了解~
  9. linux mysql 挂马_linux服务器被挂马
  10. mysql geometry 维度_使用MySQL的geometry类型处理经纬度距离问题的方法
  11. List的Stream流操作
  12. 手机怎么打开psd文件(实用方法)
  13. 3D MAX卸载“windows找不到文件”的解决办法
  14. SQL 触发器 简记
  15. 查看php是否支持sg11,云虚拟主机支持SG11扩展
  16. 苹果App Store搜索出Bug,网友:完美避开所有正确答案
  17. 2021牛客暑期多校训练营10 F.Train Wreck(栈,并查集,优先队列,贪心)
  18. android nfc 启动流程,android-NFC-如何使用NDEF_DISCOVERED启动应用程序
  19. RPC框架简析--Pigeon
  20. python爬虫面试题集锦及答案

热门文章

  1. 什么情况创建索引?什么情况不创建索引?MySQL如何避免索引失效?
  2. Objective-C Runtime (三):Method Swizzling(方法替换)
  3. Generator 简介
  4. WordPress 4.8.2 升级维护版本发布
  5. 【转】linux命令:ifconfig命令
  6. 表likp新增第一次过账输入日期字段,vl02n/vl01n/vl03n/vl06o的增强
  7. Java快速开发框架LML简介
  8. react 改变css样式_web前端入门到实战:编写CSS代码的8个策略,资深开发工程师总结...
  9. 信息学奥赛一本通(1149:最长单词2)
  10. 信息学奥赛一本通(2039:【例5.6】冒泡排序)