Lighttpd fastcgi related configuration

Fastcgi.conf

server.modules += ( "mod_fastcgi" )

##############################################################
#fastcgi.server = ( ".fcgi" =>(

fastcgi.debug = 1
fastcgi.server = (
  ".fcgi" => (
   "local" => (
   "socket" => "/tmp/fcgi.socket",
    "checklocal" => "disable",
    "bin-path" => server_root + "/cgi-bin/zb.fcgi",
    "idle-timeout" => 20,
    "min-procs" => 1,
    "max-procs" => 1
   )
  )
)

##############################################################

The communication between the fastcgi program and Lighttpd is   handled "socket" => "/tmp/fcgi.socket"by the  program. "bin-path" => server_root + "/cgi-bin/zb.fcgi"After the fastcgi program is successfully compiled, it is placed in the cgi-bin directory. Note that the two processes of Lighttpd and cgi can be run correctly only when the program is correct, otherwise it will fail.

Add alias.url += ( "/cgi-bin" => server_root + "/cgi-bin" ) to the configuration file to find the program in the current cgi-bin directory


Additional fastcgi program example

static void *Doit(void *a)
{
    int rc, i, thread_id = (int)a;
    pid_t pid = getpid();
    FCGX_Request request;
    char *server_name;


    FCGX_InitRequest(&request, 0, 0);


    for (;;)
    {
        static pthread_mutex_t accept_mutex = PTHREAD_MUTEX_INITIALIZER;
        static pthread_mutex_t counts_mutex = PTHREAD_MUTEX_INITIALIZER;


        /* Some platforms require accept() serialization, some don't.. */
        pthread_mutex_lock(&accept_mutex);
        rc = FCGX_Accept_r(&request);
        pthread_mutex_unlock(&accept_mutex);


        if (rc < 0)
            break;


       
ParseRequest(&request);
#if 0
        server_name = FCGX_GetParam("SERVER_NAME", request.envp);


        FCGX_FPrintF(request.out,
            "Content-type: text/html\r\n"
            "\r\n"
            "<title>FastCGI Hello! (multi-threaded C, fcgiapp library)</title>"
            "<h1>FastCGI Hello! (multi-threaded C, fcgiapp library)</h1>"
            "Thread %d, Process %ld<p>"
            "Request counts for %d threads running on host <i>%s</i><p><code>",
            thread_id, pid, THREAD_COUNT, server_name ? server_name : "?");


        ///sleep(2);


        pthread_mutex_lock(&counts_mutex);
        ++counts[thread_id];
        for (i = 0; i < THREAD_COUNT; i++)
            FCGX_FPrintF(request.out, "%5d " , counts[i]);
        pthread_mutex_unlock(&counts_mutex);
#endif
        FCGX_Finish_r(&request);
    }


    return NULL;
}
int main(void)
{
int i, result;
    pthread_t id[THREAD_COUNT];


FCGX_Init();


    for (i = 1; i < THREAD_COUNT; i++)
        pthread_create(&id[i], NULL, Doit, (void*)i);


    Doit(0);

}


ParseRequest(&request);  根据你自己的情况去改写该函数进行解析即可

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325906324&siteId=291194637