I’m trying to write a c++ fastcgi program to be served by nginx. I’ve got the program compiling, and the hello world example works, but I can’t seem to get any of the environment variables (REQUEST_METHOD), etc. from nginx. As far as I can tell, I’m following tutorials and have the same configuration, so I’m really pulling out my hair here as to why it’s not working. Here’s my configuration:
location /cgi {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.html;
include /etc/nginx/fastcgi_params;
}
(the fastcgi_params is unchanged from the default nginx install).
Then the relevant code from the c++ program:
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;
}
The call to FCGX_GetParam returns null, and when I output the request.envp, the only variable shown is FCGI_ROLE=RESPONDER.
I’m using the following command to launch the process:
spawn-fcgi -p 9000 -n FCGI-App
Everything is running under Ubuntu 11.10.
Any ideas?
You are trying to print
char **envp;withcout << *request.envp. This is expected to print only first string from the array, no surprise here.Try the code form official FCGI example instead: