windows环境下apache执行C++ FCGI

windows环境下apache执行C++ FCGI

      开始搞服务器这块就愈发觉得linux方便,老大要求用fastcgi写服务,在linux下很快就能搭好环境调通,而到了windows下就很麻烦,nginx也好apache也好典型的应用场景并不是在windows上,倒腾了一上午nginx也没把流程走通,spawn-cgi程序运行不了,FCGI库里自带的cgi-fcgi则是直接运行错误。好在转投apache之后基本可以跑起来,剩下的服务实现部分实际也以前做的差不了多少。在网上找解决方案的过程中,一方面觉得似乎php的实现更为常见,一方面国外的资料比国内的无意义转载靠谱。参考 配置方案把环境搭好了,只是文章后面提到了采用FCGI模块可以再外部执行从而调试程序,而实际运行中fcgi程序似乎是不能单独运行。而在基本配置方案中,下载好模块,添加剂module目录,按格式修改apache配置文件就好了。
    
Download from http://httpd.apache.org/download.cgi#mod_fcgid the latest
Windows zip file and unpack as it instructs you to, over the installed Apache
directory. This puts the mod_fcgid.* files under the current /modules
directory of Apache.

1.1.2 Now, mod_fcgid is ready to be used as soon as we load it with Apache.

1.1.3 If you have not done so yet, compile your FCGI application.

1.1.4 Then, edit the Apache /conf/httpd.conf file and add to the end:
############
LoadModule fcgid_module "modules/mod_fcgid.so"
<IfModule mod_fcgid.c>
  <Directory "<Path_To_Your_FCGI_application>">
    SetHandler fcgid-script
#    Options +ExecCGI  <- not needed if ScriptAlias is used below
    Order allow,deny
    Allow from all
  </Directory>
#optionally, to shorten the URL and to not display the executable file name
#(if ScriptAlias is used, no +ExecCGI is needed above)
  ScriptAlias /myfcgid "<Path_To_Your_FCGI_application>/<Your_FCGI_application>"
</IfModule>
############
Example:
LoadModule fcgid_module "modules/mod_fcgid.so"
<IfModule mod_fcgid.c>
  <Directory "C:/My Programs/LazarusFCGITest">
    SetHandler fcgid-script
    Order allow,deny
    Allow from all
  </Directory>
  ScriptAlias /myfcgid "C:/My Programs/LazarusFCGITest/helloworld.exe"
</IfModule>

Note, there are many ways to configure the FCGI applications, this is just but
one example. You can check the Apache and mod_fcgid documentation for
alternatives.

1.1.5 Start/Restart your Apache server so it will load your FCGI application.
If everything went according to plan, your FCGI application should be listed
in the Windows task manager as running.

1.1.6 Open your web browser and try to call your new FCGI application.
Example:
http://127.0.0.1:8080/myfcgid/func1call
or
http://127.0.0.1/myfcgid/func1call
depending on your Apache installation and configuration. "myfcgid" is the
ScriptAlias name specified for the FCGI application, func1call is the action
name we want to call within our default web module. If you have multiple web
modules, you can enter the desired web module name before the action name, for
example:
http://127.0.0.1:8080/myfcgid/webmodule1/func1call
or
http://127.0.0.1/myfcgid/webmodule1/func1call

If there is any problem, you can try and check the Apache error.log for clues.

你可能感兴趣的:(windows环境下apache执行C++ FCGI)