thttpd+cgilua
来源:互联网 发布:plc编程语言 编辑:程序博客网 时间:2024/05/21 09:37
PC安装
1: 下载thttpd: http://acme.com/software/thttpd/
2: 参考前面文章安装kepler/xavante (实际上要不了那么多lua module,但这种方式安装最简单),或者只安装如下module:
wsapi cgilua md5 luasocket (luaexpat)
3: 创建www组
groupadd www
usermod -G alex www
4: 进入thttpd目录
./configure
make
make install
5: 创建www目录
mkdir /www
cd /www
cp -rf /usr/local/www/cgi-bin .
cp /usr/local/bin/cgilua.cgi ./cgi-bin/cgi
6: 配置文件
vi thttpd.conf
port=80
user=nobody
dir=/www
nochroot
cgipat=/cgi-bin/*
logfile=/www/thttpd.log
7:将网页相关文件放入到/www目录, 目录结构如下:
/usr/local/sbin/
thttpd/www/
thttpd.conf
test.lp
cgi-bin/
cgi
当然,你可将配置文件放到其他目录
8: 运行
/usr/local/sbin/thttpd -C /www/thttpd.conf
9:在浏览器中按如下方式输入
http://192.168.100.119/cgi-bin/cgi/test.lp
嵌入式
1: 不需要用到权限验证
config.h 屏蔽
/*#define AUTH_FILE ".htpasswd"*/
libhttpd.c
#ifdef AUTH_FILE
extern char* crypt( const char* key, const char* setting );
#endifMakefile
LIBS =
2: 传递AUTHORIZE信息给cgi服务
libhttpd.c cgi_child函数:
if ( hc->authorization[0] != '/0' )
{
envp[envn++] = build_env( "AUTH_TYPE=%s", "Basic" );
envp[envn++] = build_env( "AUTHORIZATION=%s",hc->authorization);
}
3: 调用cgi时,限制只有lp的文件才需要交给cgi,其它文件仍然由thttpd处理(此处默认cgi为cgilua.cgi, cgilua文件后缀为lp)
由于cgi调用非常耗cpu和内存,如果一个lp文件中包含图片,js等时,会造成cpu和内存的浪费,故在此处直接屏蔽掉。
在此基础之上,再限制cgi的连接数,见下面说明。
libhttpd.c really_start_request函数判断是否调用cgi时修改如下:
/* Is it world-executable and in the CGI area? */
if ( hc->hs->cgi_pattern != (char*) 0 &&
( hc->sb.st_mode & S_IXOTH ) &&
match( hc->hs->cgi_pattern, hc->expnfilename ) )
{
if((hc->encodedurl == (char*)0 )
|| (strstr(hc->encodedurl, ".lp") != (char*)0)
|| (strcmp(hc->expnfilename, "/cgi-bin/cgi") == -1))
return cgi( hc );
else
{
char szbuf[256];
//source url="/cgi-bin/cgi/img/spacer.gif"
//strlen("/cgi-bin/cgi") = 12
//expnfilename="img/spacer.gif"
//encodedurl="/img/spacer.gif"
(void)strcpy(szbuf, hc->encodedurl + 12);
httpd_realloc_str(&hc->expnfilename, &hc->maxexpnfilename, strlen(szbuf));
(void)strcpy(hc->expnfilename, szbuf+1);
httpd_realloc_str(&hc->encodedurl, &hc->maxencodings, strlen(szbuf));
(void)strcpy(hc->encodedurl, szbuf);
stat( hc->expnfilename, &hc->sb );
hc->pathinfo[0]='/0';
if(hc && hc->hs && hc->hs->logfp && hc->expnfilename)
{
(void) fprintf( hc->hs->logfp,"new file: %s method: %s url:%s/n", hc->expnfilename, httpd_method_str( hc->method ), hc->encodedurl );
}
}
}
4: 编译
(本来试图用configure搞定的,但其对host支持好像不是很好,修改如下)
./configure --prefix=/home/alex/thttpd/build
vi Makefile
CC=arm-linux-uclibc-gcc
make
make install
当然,如果要用到thttpd提供的几个小工具,也需要按照上面方法修改
常见问题
1:最好关闭防火墙和selinux
service iptables stop
setenforce 0
2:出现500错误, 最快最方便解决办法:
chmod -R 777 /www
3: 需要加入权限验证
cd /www/cgi-bin
/usr/local/sbin/htpasswd c .htpasswd admin此时会提示你输入用户名和密码
4: 注意控制文件的权限
对于目录建议使用777
对于文件,建议使用666
对于cgi-bin下,建议使用777、
5:限制cgi的连接数, 在thttpd.conf加入
cgilimit=4
6:针对每次cgi访问,thttpd都会启动一个新进程去执行,所以如果网页中文件太多或者连续点击次数太多,内存和CPU会占用较多。
如果针对嵌入式开发,建议多用html,少用cgi,同时cgi文件中,如果有图片或者js,也会产生一次cgi调用的,还有如果url中是安装如下格式输入 http://192.168.1.1/cgi-bin/cgi/filename
即使filename是html文件,也会产生cig调用。如果不想被调用cgi,请见上面修改
同时,最好限制cgi的连接数
原文地址 http://blog.csdn.net/dragoncheng/article/details/5614559
- thttpd+cgilua
- thttpd+cgilua
- thttpd
- thttpd
- thttpd 笔记
- thttpd配置
- thttpd服务器
- thttpd 安装
- thttpd源码
- thttpd+cgi
- thttpd + Cgicc
- 移植thttpd web服务器
- thttpd 服务器移植
- 移植 thttpd Web服务器
- 移植thttpd服务器
- thttpd安装与调试
- THTTPD CGI 使用手册
- thttpd.Timer.c分析
- BT通信
- C语言之冒泡排序、选择排序
- LINUX C 下使用 nlpir 中英文分词
- Angular Light 指令用法
- 如何使用unity中Resources文件
- thttpd+cgilua
- 亲自实践:.多进程Application onCreate多次执行
- 让进程安全地退出
- 201603211942
- java语言程序设计第十版(Introduce to java) 课后习题 chapter6-14
- 安卓介绍
- oracle 分组函数
- Android新手入门2016(10)--GridView
- iOS 让只支持竖屏的App横屏播放网页视频