最近想選一個web server當作基礎平台.看過了boa, thttpd, mini_httpd, lighthttpd...最後選擇了thttpd.原因是我覺得它夠簡單.省去我理解程式的時間.功能也符合需求.
$ thttpd -d /home/web -c cgi-bin/**.cgi -l /var/log/thttpd.log (-D)
timer.c : time scheduler (hash arrary with link-list)
fdwatch.c : watching file descriptors
tdate_parse.c : parsing date string to time structure
match.c : string comparing that support |, *, ?, /
log system: use syslog or file
or try thttpd.conf: thttpd -C thttpd.conf
dir=/home/web
chroot
logfile=/var/log/thttpd.log
pidfile=/var/run/thttpd.pid
charset=iso-8859-15
cgipat=**.cgi
CGI輸出環境變數範例:
#include <stdio.h> #include <stdlib.h> #include <string.h> char HTTP_EVNS[][64] = { "PATH", "LD_LIBRARY_PATH", "SERVER_SOFTWARE", "SERVER_NAME", "GATEWAY_INTERFACE", "SERVER_PROTOCOL", "SERVER_PORT", "REQUEST_METHOD", "PATH_INFO", "PATH_TRANSLATED", "SCRIPT_NAME", "QUERY_STRING", "REMOTE_ADDR", "HTTP_REFERER", "HTTP_USER_AGENT", "HTTP_ACCEPT", "HTTP_ACCEPT_ENCODING", "HTTP_ACCEPT_LANGUAGE", "HTTP_COOKIE", "CONTENT_TYPE", "HTTP_HOST", "CONTENT_LENGTH", "REMOTE_USER", "AUTH_TYPE", "TZ", "CGI_PATTERN", }; int main( int argc, char* argv[] ) { int i, total; printf( "Content-type: text/html\nStatus: 200/html\n\n<HTML><HEAD><TITLE>EVN List</TITLE></HEAD>\n"); total = sizeof(HTTP_EVNS)/sizeof(HTTP_EVNS[0]); for(i = 0; i < total; ++i ) { printf("%s=%s<BR>\n", HTTP_EVNS[i], getenv(HTTP_EVNS[i])); } printf( "<BODY>\n</BODY></HTML>\n" ); exit( 0 ); }
輸出範例:
PATH=/usr/local/bin:/usr/ucb:/bin:/usr/bin
LD_LIBRARY_PATH=(null)
SERVER_SOFTWARE=thttpd/2.25b
29dec2003
SERVER_NAME=192.168.3.6
GATEWAY_INTERFACE=CGI/1.1
SERVER_PROTOCOL=HTTP/1.1
SERVER_PORT=80
REQUEST_METHOD=GET
PATH_INFO=(null)
PATH_TRANSLATED=(null)
SCRIPT_NAME=/cgi-bin/env.cgi
QUERY_STRING=(null)
REMOTE_ADDR=192.168.1.254
HTTP_REFERER=(null)
HTTP_USER_AGENT=Mozilla/4.0
(compatible; MSIE 8.0; Windows NT 5.1; Trident/4.0; .NET CLR 1.1.4322; .NET CLR
2.0.50727; .NET CLR 3.0.4506.2152; .NET CLR 3.5.30729; OfficeLiveConnector.1.3;
OfficeLivePatch.0.0)
HTTP_ACCEPT=image/gif, image/jpeg, image/pjpeg,
image/pjpeg, application/x-shockwave-flash, application/vnd.ms-excel,
application/vnd.ms-powerpoint, application/msword, application/x-ms-application,
application/x-ms-xbap, application/vnd.ms-xpsdocument, application/xaml+xml,
*/*
HTTP_ACCEPT_ENCODING=(null)
HTTP_ACCEPT_LANGUAGE=zh-tw
HTTP_COOKIE=(null)
CONTENT_TYPE=(null)
HTTP_HOST=192.168.3.6
CONTENT_LENGTH=(null)
REMOTE_USER=(null)
AUTH_TYPE=(null)
TZ=(null)
CGI_PATTERN=cgi-bin/*.cgi
留言列表