Lighttpd fastcgi相关配置

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
   )
  )
)

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

fastcgi程序和Lighttpd之间的通讯是通过 "socket" => "/tmp/fcgi.socket"用 "bin-path" => server_root + "/cgi-bin/zb.fcgi" 程序来处理。fastcgi程序编译成功后放入到cgi-bin目录中,注意,该程序正确时,才能正确运行Lighttpd和cgi两个进程,否则都不能成功。

在该配置文件中加入alias.url += ( "/cgi-bin" => server_root + "/cgi-bin" ),才能在当前cgi-bin目录中找到程序


附加fastcgi程序示例

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);  根据你自己的情况去改写该函数进行解析即可

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

一水遮夏211

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值