0

I am using this script.c:

#include <fcgi_stdio.h>
#include <stdlib.h>
int main (void) {
while (FCGI_Accept() >= 0) {
    printf("Status: 200 OK\r\n");
    printf("Content-type: text/html\r\n\r\n");
    printf("<!doctype><html><body>Welcome!</body></html>\n");
}
return EXIT_SUCCESS;
}

I compile it using

gcc script.c -o script.fcgi -lfcgi -O3 -Wall -Wextra -pedantic -std=c11

Then, I put in terminal:

 cgi-fcgi -start -connect localhost:9000 script.fcgi
 cgi-fcgi -connect localhost:9000 script.fcgi

and get output

Status: 200 OK
Content-type: text/html

<!doctype><html><body>Welcome!</body></html>

After that, I used curl

 curl localhost:9000
 curl: (52) Empty reply from server

and telnet

 telnet localhost 9000
 Connected to localhost.
 GET / HTTP/1.1
 Connection closed by foreign host.

Why I got success result with cgi-fcgi only? How to use curl and telnet to obtain the same data from script?

1 Answers1

3

FastCGI is not HTTP, which is why curl won't work (at least not with http (default) URLs).

This is also why your telnet example is not working (because you're talking HTTP to it).

While curl does support a (very!) wide variety of protocols, FastCGI is not one of them.

The FastCGI protocol is not particularly trivial; its a binary protocol to begin with, designed to connect to a web-server, not to a regular HTTP client.

If you're wanting something you can point a browser at without have the webserver up and running, you'll need some sort of bridge (which is what a webserver would be doing). Keep cgi-fcgid to help you troubleshoot any webserver configuration issues.

Cameron Kerr
  • 4,069
  • 19
  • 25