http://www.acme.com/software/thttpd/ 获取thttpd 我下载了最新的 version 2.25b
放入~/thttpd文件夹中,可以放入任何文件夹中
$ cd ~/thttpd
$ tar -zxvf thttpd-2.25b.tar.gz
$ cd ./thttpd-2.25b/
看一下如何安装 more INSTALL
基本的三个步骤:
$ ./configure $ make $ make install
开始执行:
$ ./configure 一切正常,生成了Makefile
$ make
htpasswd.c:52:12: 错误: 与‘getline’类型冲突
/usr/include/stdio.h:675:20: 附注: ‘getline’的上一个声明在此
发生了一个错误,仔细分析一下,htpasswd.c中的名称与stdio.h标准库中的getline的名称一样,所以导致了冲突。
修改的方法是到htpasswd.c中,修改getline。htpasswd.c中getline是一个static类型的函数,函数只会出现在本文件中。依次查找getline,并修改成get_line。htpasswd.c文件在 ./thttpd-2.25b/extras 文件夹中。
$ sudo make install
这样thttpd已经被安装到制定了文件夹里了。
看一下Makefile
$ more Makefile
有如下几行
prefix = /usr/local
exec_prefix = ${prefix}
BINDIR = ${exec_prefix}/sbin
MANDIR = ${prefix}/man
WEBDIR = $(prefix)/www
WEBGROUP = www
CGIBINDIR = $(WEBDIR)/cgi-bin
可执行文件在/usr/local/sbin/ ; WEB目录在/usr/local/www/ ; CGI目录在/usr/local/www/cgi-bin/ ;
安装好之后,需要进行一些配置,可以参考thttpd的官网http://www.acme.com/software/thttpd/notes.html
建立几个目录
$ cd /usr/local/www/
$ sudo mkdir logs
$ sudo mkdir cgi-bin
$ sudo touch thttpd_log
建立脚本,放到指定目录下
- Startup script.
Put this into a file called thttpd.sh in /usr/local/etc/rc.d, and make sure it's executable.
#!/bin/sh if [ -x /usr/local/sbin/thttpd_wrapper ] ; then echo -n " thttpd" /usr/local/sbin/thttpd_wrapper & fi
- Wrapper script.
The -D flag tells thttpd to not put itself into the background, and the -C flag tells it to get the rest of its configuration from the specified config file. Again, make sure the script is executable.
#!/bin/sh while true ; do /usr/local/sbin/thttpd -D -C /usr/local/www/thttpd_config sleep 10 done
- Config file.
create the directory/usr/local/www if necessary and then put this into /usr/local/www/thttpd_config:dir=/usr/local/www/data chroot cgipat=/usr/local/www/cig-bin/**.cgi logfile=/usr/local/www/logs/thttpd_log pidfile=/var/run/thttpd.pid
启动服务器
$ /usr/local/etc/rc.d$ sudo ./thttpd.sh
在/usr/local/www/data中放入一个.html 文件,在浏览器中输入http://127.0.0.1/ ,可以到看放入的网页。
在 /usr/local/www/data 中,index.html 名称的网页是默认作为主页的。如果是其他的名称,则索引到网页所在的文件夹目录。
/******************************************************************************************/
CGI