[강좌] fastcgi의 fcgi examples (C 언어) 테스트
간단하고 쉬운것이지만,
나름데로 시간을 투자해서 테스트를 해본거라.
글을 남깁니다.
제 시스템 환경
OS : kubuntu dapper
fcgi-2.4.0
apache2
관련 설치 패키지:
libapache2-mod-fastcgi
libfcgi-dev
libfcgi0
1. fcgi-2.4.0.tar.gz 를 받습니다.
(http://fastcgi.com/)
2. 임의의 디렉토리에 풀고, 컴파일합니다.
$ tar -xvzf fcgi-2.4.0.tar.gz $ cd fcgi-2.4.0 $ ./configure $ make
3. 컴파일된 바이너리확인.
"fcgi-2.4.0/examples/.libs" 위치에 바이너리가 존재합니다.
$ ls examples/.libs authorizer* echo* echo-cpp* echo-x* log-dump* size* threaded*
자~ 이제 컴파일은 잘 되었고...
아파치 설정을 봅니다.
4. 아파치가 떠있는지 확인 합니다.
cgi가 잘 도는지도 확인 할겸...
브라우져를 띄우고 다음과 같이 써봅니다.
컴퓨터의 환경값들이 출력되면 테스트가 잘된것 입니다.
[참고] kubuntu는 cgi-bin 디렉토리는 "/usr/lib/cgi-bin"에 위치합니다.
5. fastcgi 모듈이 apache에 잘 등록되었는지 확인.
$ cat /etc/apache2/mods-enabled/fastcgi.conf <IfModule mod_fastcgi.c> AddHandler fastcgi-script .fcgi # FastCgiWrapper /usr/lib/apache2/suexec2 FastCgiIpcDir /var/lib/apache2/fastcgi </IfModule> $ cat /etc/apache2/mods-enabled/fastcgi.load LoadModule fastcgi_module /usr/lib/apache2/modules/mod_fastcgi.so dhjang@pug:/etc/apache2/mods-enabled
6. examples에 있는 바이너리를 cgi-bin에 복사합니다.$ sudo cp -rvf fcgi-2.4.0/examples/.libs/echo-x /usr/lib/cgi-bin/echo-x.fcgi
주의 할것은 .fcgi의 확장자를 붙여줘야 fastcgi로 인식한다는겁니다.
echo-x.c는 맨밑에 첨부하겠습니다.
7. echo-x.fcgi를 실행 시켜보자~ :-)
다음과 같이 웹 브라우져에 URL입력을 해봅니다.
환경변수들이 출력되는것을 보면, 성공~
Request number 50, Process ID: 5900
위과 같이 프로세스 아이디가 표시되고,
더있는 프로세스 아이디에 요청된 횟수가 표시됩니다.
threaded도 threaded.fcgi로 복사해서 테스트 해보세요~
재밌습니다. :-)
- 끝 -
/*
* echo2.c --
*
* Produce a page containing all the inputs (fcgiapp version)
*
*
* Copyright (c) 1996 Open Market, Inc.
*
* See the file "LICENSE.TERMS" for information on usage and redistribution
* of this file, and for a DISCLAIMER OF ALL WARRANTIES.
*
*/
#ifndef lint
static const char rcsid[] = "$Id: echo-x.c,v 1.1 2001/06/19 15:06:17 robs Exp $";
#endif /* not lint */
#include "fcgi_config.h"
#include <stdlib.h>
#ifdef HAVE_UNISTD_H
#include <unistd.h>
#endif
#ifdef _WIN32
#include <process.h>
#else
extern char **environ;
#endif
#include "fcgiapp.h"
static void PrintEnv(FCGX_Stream *out, char *label, char **envp)
{
FCGX_FPrintF(out, "%s:<br>\n<pre>\n", label);
for( ; *envp != NULL; envp++) {
FCGX_FPrintF(out, "%s\n", *envp);
}
FCGX_FPrintF(out, "</pre><p>\n");
}
int main ()
{
FCGX_Stream *in, *out, *err;
FCGX_ParamArray envp;
int count = 0;
while (FCGX_Accept(&in, &out, &err, &envp) >= 0) {
char *contentLength = FCGX_GetParam("CONTENT_LENGTH", envp);
int len = 0;
FCGX_FPrintF(out,
"Content-type: text/html\r\n"
"\r\n"
"<title>FastCGI echo (fcgiapp version)</title>"
"<h1>FastCGI echo (fcgiapp version)</h1>\n"
"Request number %d, Process ID: %d<p>\n", ++count, getpid());
if (contentLength != NULL)
len = strtol(contentLength, NULL, 10);
if (len <= 0) {
FCGX_FPrintF(out, "No data from standard input.<p>\n");
}
else {
int i, ch;
FCGX_FPrintF(out, "Standard input:<br>\n<pre>\n");
for (i = 0; i < len; i++) {
if ((ch = FCGX_GetChar(in)) < 0) {
FCGX_FPrintF(out,
"Error: Not enough bytes received on standard input<p>\n");
break;
}
FCGX_PutChar(ch, out);
}
FCGX_FPrintF(out, "\n</pre><p>\n");
}
PrintEnv(out, "Request environment", envp);
PrintEnv(out, "Initial environment", environ);
} /* while */
return 0;
}

댓글 달기