nginx에서 제공하는 C++ fastcgi 프로그램을 작성하려고합니다. 나는 프로그램을 컴파일하고 hello world 예제가 작동하지만, nginx에서 환경 변수 (REQUEST_METHOD)를 얻을 수 없다. 제가 말할 수있는 한, 자습서를 따르고 동일한 구성을 가지고 있으므로 실제로 작동하지 않는 이유에 관해서 여기에서 제 머리카락을 꺼내고 있습니다. 여기에 내 구성 :nginx로 C++에서 fastcgi로 환경 변수에 액세스하기
location /cgi {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.html;
include /etc/nginx/fastcgi_params;
}
(fastcgi_params는 기본 nginx 설치에서 변경되지 않음)입니다.
이어서 해당 코드에서 C++ 프로그램 : I 출력 request.envp 도시 유일한 변수 FCGI_ROLE = 응답자 때
streambuf * cin_streambuf = cin.rdbuf();
streambuf * cout_streambuf = cout.rdbuf();
streambuf * cerr_streambuf = cerr.rdbuf();
FCGX_Request request;
FCGX_Init();
FCGX_InitRequest (&request, 0, 0);
while (FCGX_Accept_r (&request) == 0)
{
fcgi_streambuf cin_fcgi_streambuf (request.in);
fcgi_streambuf cout_fcgi_streambuf (request.out);
fcgi_streambuf cerr_fcgi_streambuf (request.err);
#if HAVE_IOSTREAM_WITHASSIGN_STREAMBUF
cin = &cin_fcgi_streambuf;
cout = &cout_fcgi_streambuf;
cerr = &cerr_fcgi_streambuf;
#else
cin.rdbuf(&cin_fcgi_streambuf);
cout.rdbuf(&cout_fcgi_streambuf);
cerr.rdbuf(&cerr_fcgi_streambuf);
#endif
//figure out what kind of request we have
char * request_type = FCGX_GetParam("REQUEST_METHOD", request.envp);
cout << "Content-type: text/html\r\n"
"\r\n";
cout << "Environment is: " << *request.envp;
}
FCGX_GetParam에 대한 호출이 null 반환하고.
나는 프로세스를 시작하려면 다음 명령을 사용하고 있습니다 :
spawn-fcgi -p 9000 -n FCGI-App
모든 우분투 11.10에서 실행됩니다.
아이디어가 있으십니까?
그냥 추측 :
대신 코드 형태 official FCGI example를 시도? –