fastcgi apache fcgi

來源:互聯網
上載者:User

 FastCGI 安裝與配置
相關軟體包:
httpd 2.2.14      //注意版本 這個版本不會出問題   註:apache httpd安裝 

fcgi-2.4.0.zip
mod_fastcgi-2.4.6.zip 請仔細閱讀其中的README 

php 5.2.17

配置apache: (預設安裝在/usr/local 檔案夾下)

#配置httpd.conf 尾部添加 :
LoadModule fastcgi_module modules/mod_fastcgi.so
<IfModule fastcgi_module>
AddHandler fastcgi-script .fcgi # you can put whatever extension you want
</IfModule>
FastCgiIpcDir /tmp

#可以限制fcgi數目 和 連結時間:
FastCgiServer /root/fcgi/test.fcgi -processes 1 -idle-timeout 1000

# : -processes 1 只允許開啟一個進程 適合gdb調試 -idle-timeout 1000 連線逾時時間1000s 適合gdb調試

#修改fcgi目錄
ScriptAlias /cgi-bin/ "/usr/local/apache2/cgi-bin/"<Directory "<Directory "/usr/local/apache2/cgi-bin">
</Directory>

 

配置參考地址:http://www.fastcgi.com/mod_fastcgi/docs/mod_fastcgi.html#FastCgiServer

test.c:(簡單樣本不推薦)

#include <fcgi_stdio.h>
#include <stdlib.h>
int $count =0;
int main( int argc, char*argv[] )
{
while (FCGI_Accept() >=0) {
FCGI_printf("Content-Type:text/html\n\n");
FCGI_printf("hello world\n\n");
}
}

  編譯:

gcc -Wall -g -O0  test.c -o test.fcgi -lfcgi

 

訪問: http://localhost/cgi-bin/test.fcgi

test2.c(推薦)

 

/* Compile with: gcc -Wall -lfcgi fastcgi.c -o fastcgi 
*/

#include <stdio.h>
#include <stdlib.h>
#include <fcgiapp.h>

#define printf(...) FCGX_FPrintF(request->out, __VA_ARGS__)
#define get_param(KEY) FCGX_GetParam(KEY, request->envp)

void handle_request(FCGX_Request *request) {
char*value;

printf("Content-Type: text/plain\r\n\r\n");
if ((value = get_param("REQUEST_METHOD")) != NULL) {
printf("%s ", value);
}
if ((value = get_param("REQUEST_URI")) != NULL) {
printf("%s", value);
}
if ((value = get_param("QUERY_STRING")) != NULL) {
printf("?%s", value);
}
if ((value = get_param("SERVER_PROTOCOL")) != NULL) {
printf(" %s", value);
}
printf("\n");
}

int main(void) {
//int sock;
FCGX_Request request;

FCGX_Init();
//sock = FCGX_OpenSocket(":2005", 5);
FCGX_InitRequest(&request, 0, 0);

while (FCGX_Accept_r(&request) >=0) {
handle_request(&request);
FCGX_Finish_r(&request);
}

return EXIT_SUCCESS;
}

 

  

 

編譯  Makefile:

all:main
main: test.c
gcc -g -Wall -O0 -lfcgi -o test.fcgi test.c

//注意gcc前面用tab代替空格

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.