lighttpd 安装运行
lighttpd 下载地址
编译按照文件INSTALL 来操作
ReadMe 有使用方法
lighttpd -f <.conf>
清除运行的进程
killall lighttpd
lighttpd config 配置
在doc/config/lighttpd.conf 修改
var.log_root = "/server/log"
var.server_root = "/server/www"
var.state_dir = "/server/www"
var.home_dir = "/server/www"
var.conf_dir = "/server/config"
server.port = 8080
server.bind = "localhost"
server.document-root = server_root
https://redmine.lighttpd.net/projects/lighttpd/wiki/Docs lighttpd wiki
cgi 配置
/www/cgi-bin目录下添加文件
gcc hello.c -o hello.cgi
#include "stdio.h"
int main(void) {
printf( "Content-Type: text/plain\n\n" );
printf("Hello world !\n");
return 0;
}
config/modules.conf
include "conf.d/fastcgi.conf"
##
## plain old CGI (mod_cgi)
##
include "conf.d/cgi.conf"
config/conf.d/cgi.conf 添加
alias.url += ( "/cgi-bin" => server_root + "/cgi-bin" )
$HTTP["url"] =~ "^/cgi-bin" {
cgi.assign = ( "" => "" )
}
重启lighttpd
fastcgi 配置
fastcgi GitHub 地址 https://github.com/FastCGI-Archives/fcgi2
config/conf.d/fastcgi.conf
fastcgi.server = (
"/login" => (
"test.fastcgi.handler" => (
"socket" => socket_dir + "test.fastcgi.socket",
"check-local" => "disable",
"bin-path" => server_root + "/fcgi-bin/test.fastcgi",
"max-procs" => 30,
)
),
"/helloworld" =>(
"skeleton.fcgi.handler" => (
"socket" => socket_dir + "skeleton.fcgi.socket",
"check-local" => "disable",
"bin-path" => server_root + "/fcgi-bin/skeleton.fcgi",
"max-procs" => 30,
)
)
)
C FastCGI skeleton
// gcc -o skeleton.fcgi skeleton.c -lfcgi
#include <fcgi_stdio.h>
int main (void) {
while (FCGI_Accept() >= 0) {
printf("Status: 200 OK\r\n\r\nHello World!\n");
}
return 0;
}
C/C++ FastCGI on lighttpd named socket
// gcc testfastcgi.c -o test.fastcgi -lfcgi
#include <stdlib.h>
#include <string.h>
#include <syslog.h>
#include <alloca.h>
#include <fcgiapp.h>
#define LISTENSOCK_FILENO 0
#define LISTENSOCK_FLAGS 0
int main(int argc, char** argv) {
openlog("testfastcgi", LOG_CONS|LOG_NDELAY, LOG_USER);
int err = FCGX_Init(); /* call before Accept in multithreaded apps */
if (err) { syslog (LOG_INFO, "FCGX_Init failed: %d", err); return 1; }
FCGX_Request cgi;
err = FCGX_InitRequest(&cgi, LISTENSOCK_FILENO, LISTENSOCK_FLAGS);
if (err) { syslog(LOG_INFO, "FCGX_InitRequest failed: %d", err); return 2; }
while (1) {
err = FCGX_Accept_r(&cgi);
if (err) { syslog(LOG_INFO, "FCGX_Accept_r stopped: %d", err); break; }
char** envp;
int size = 200;
for (envp = cgi.envp; *envp; ++envp) size += strlen(*envp) + 11;
char* result = (char*) alloca(size);
strcpy(result, "Status: 200 OK\r\nContent-Type: text/html\r\n\r\n");
strcat(result, "<html><head><title>testcgi</title></head><body><ul>\r\n");
for (envp = cgi.envp; *envp; ++envp) {
strcat(result, "<li>");
strcat(result, *envp);
strcat(result, "</li>\r\n");
}
strcat(result, "</ul></body></html>\r\n");
FCGX_PutStr(result, strlen(result), cgi.out);
}
return 0;
}
参考来自https://redmine.lighttpd.net/projects/lighttpd/wiki/Docs_ModFastCGI