2012/10/4 Ville Valkonen <[email protected]>:
> Hi,
>
> I've configured Nginx and FCGI to run some C/C++ apps, well almost.
>
> When navitaging to http://host.foo/weezel/progut/default.cgi nginx's error log
> states the following (below there is test.c, test.c == default.cgi):
>
> 2012/10/04 16:52:22 [error] 26690#0: *14 kevent() reported that connect()
> failed (61: Connection refused) while connecting to upstream, client:
> 192.168.50.102, server: host.foo, request: "GET /weezel/progut/ HTTP/1.1",
> upstream: "fastcgi://127.0.0.1:9001", host: "host.foo"
>
> ..and browser says HTTP Error 500 (Internal Server Error). I'd say the problem
> lies somewhere in nginx configuration since nc 127.0.0.1 9001 let's
> connections
> in.
>
> So apparently I am missing something obvious here. Therefore any help will be
> appreciated. Here is the setup I've done so far:
>
Hi,
I'm not sure what you're exactly trying to do, is it cgi or fastcgi
you want to use?
i managed to get cgi working with fcgi-cgi, yet i didn't figure out how
to make use of fastcgi.
atleast under chroot i was receiving error about prematurely closed
connection while reading response header from upstream.
this was through unix socket. i launched the 'fastcgi processes'
by hand with spawn-fcgi, and saw them die one after another when
trying to access it via browser, to be clear, 1 process died per request,
and i had launched multiple w/-F arg for spawn-fcgi.
i'm not going to try debugging it any further, plain cgi is what i was after.
> [...]
>
> #### test.c
>
> #include <fcgi_stdio.h>
> #include <stdlib.h>
>
> int count;
>
> void
> initialize(void)
> {
> count=0;
> }
>
> void
> main(void)
> {
> initialize();
>
> while (FCGI_Accept() >= 0) {
> printf("Content-type: text/html\r\n"
> "\r\n"
> "<title>FastCGI Hello! (C, fcgi_stdio
> library)</title>"
> "<h1>FastCGI Hello! (C, fcgi_stdio library)</h1>"
> "Request number %d running on host <i>%s</i>\n",
> ++count, getenv("SERVER_HOSTNAME"));
> }
> }
>
i
this is what i was testing plain cgi with, while the above does work,
there is no benefit for the extra w/o fastcgi, needs to be built w/-static:
#include <stdio.h>
int
main(void)
{
printf("Content-type: text/plain\n\n");
printf("req on host %s",
getenv("SERVER_NAME"));
return 0;
}
here is my ngix.conf for testing cgi:
worker_processes 1;
events {
worker_connections 100;
}
http {
include mime.types;
default_type application/octet-stream;
keepalive_timeout 65;
server {
listen 80;
server_name 192.168.2.94;
location = /cgi-bin {
rewrite ^ /cgi-bin/ permanent;
}
location /cgi-bin/ {
fastcgi_index default.cgi;
fastcgi_pass unix:/fcgi.socket;
fastcgi_param SCRIPT_FILENAME $fastcgi_script_name;
include fastcgi_params;
}
location / {
root /htdocs;
index index.html index.htm;
}
}
}
-Artturi