最近都在玩Linux,有点体会。和大家分享下lighttpd在WebDAV的应用。在这里,我以Fedora Core 4来制作有关lighttpd的WebDAV服务器。
因为Fedora Extras的lighttpd-1.3.16-2.fc4中没有包含WebDAV的组件,所以我使用从lighttpd的官方站 (http://www.lighttpd.net/)下载的最新版”SRPM(lighttpd-1.4.10-1.src.rpm)”来制作RPM。之所以从SRPM再来制作RPM,是因为RPM的lighttpd是以SSL为OFF状态下编译完成的。
如果你下载了lighttpd-1.4.10-1.src.rpm,就在命令行下把SSL修改成如下:
# rpmbuild –rebuild –with ssl lighttpd-1.4.10-1.src.rpm |
在/usr/src/redhat/RPMS/i386里将lighttpd-1.4.10-1.i386.rpm编译好并安装。由于在yum命令行上安装Fedora Extras的lighttpd,就必须remove一下。以防保险还必须将/etc/lighttpd/lighttpd.conf做下备份。
# cp /etc/lighttpd/lighttpd.conf /etc/lighttpd.conf.org # yum remove lighttpd lighttpd-fastcgi (省略) Is this ok [y/N]: y ←「y」输入Y然后回车 # rpm -Uhv lighttpd-1.4.10-1.i386.rpm |
接下来设置SSL和Digest。
# mkdir -p /etc/lighttpd/ssl # cd /etc/lighttpd/ssl # openssl req -new -x509 -keyout server.pem -out server.pem -days 365 -nodes (省略) —– Country Name (2 letter code) [GB]:CN (国别) State or Province Name (full name) [Berkshire]:FuJian (省份) Locality Name (eg, city) [Newbury]:XXXX (市区名) Organization Name (eg, company) [My Company Ltd]:Example Corp. (公司名) Organizational Unit Name (eg, section) []:Example Dept. Common Name (eg, your name or your server's hostname) []:Plvo Marfoxs (管理者或者服务器名) Email Address []:marfoxs@gmail.com (Email等) |
接着,由htdigest命令建立用户并设置密码。
# cd /etc/lighttpd # htdigest -c lighttpd.user.htdigest “WebDAV” secret Adding password for secret in realm WebDAV. New password:qq354153 ←输入密码 在这里,我输入qq354153 Re-type new password:qq354153 ←再输入密码 |
接下来制作WebDAV用的目录文件夹,在这里用yum编译下的/srv/www/lighttpd文件夹下再建立一个dav文件夹。设置可写属性。
# mkdir -p /srv/www/lighttpd/dav # chmod 777 /srv/www/lighttpd/dav |
最后编辑/etc/lighttpd/lighttpd.conf 如果该文件不存在的话,可以从刚才备份的/etc/lighttpd/lighttpd.conf复制上去,或者复制
/usr/share/doc/lighttpd-1.4.10/lighttpd.conf 也行。
server.modules = ( (省略) “mod_fastcgi”, (省略) “mod_cgi”, (省略) “mod_webdav”, “mod_accesslog” ) ## a static document-root, for virtual-hosting take look at the ## server.virtual-* options server.document-root = “/srv/www/lighttpd/” ## where to send error-messages to server.errorlog = “/var/log/lighttpd/error_log” #### SSL engine ←设定SSL ssl.engine = “enable” ssl.pemfile = “/etc/lighttpd/ssl/server.pem” #### auth module ←设定Digest ## read authentication.txt for more info auth.backend = “htdigest” auth.backend.htdigest.userfile = “/etc/lighttpd/lighttpd.user. htdigest” auth.require = ( “/dav/” => ( “method” => “digest”, “realm” => “WebDAV”, “require” => “valid-user” ) ) $HTTP["url"] =~ “^/dav($|/)” { ←设定WebDAV webdav.activate = “enable” # webdav.is-readonly = “enable” } |
设定完之后,启动lighttpd,并确认一下。lighttpd启动之后,会要求输入密码,这时候就输入刚才输入的密码(qq354153)回车。
# service lighttpd start
lighttpd 启动中: Enter PEM pass phrase: 输入密码!
文章作者:Marfoxs
一条评论
您好!
我自己编译了lighttpd-1.4.31在ubuntu10.04下运行,用cavader这个webdav client能进入webdav server,但是在IE下登录http://localhost:8080/webdav,输入用户名和密码,返回“404 Not found”。 我的wedav的配置如下,指点下,谢谢!
server.modules += ( “mod_webdav” )
alias.url = ( “/webdav” => “/usr/local/lighttpd/upload”)
#$HTTP[“url”] =~ “^/webdav($|/)” {
$HTTP[“url”] =~ “^/webdav” {
##
## enable webdav for this location
##
webdav.activate = “enable”
##
## By default the webdav url is writable.
## Uncomment the following line if you want to make it readonly.
##
#webdav.is-readonly = “enable”
##
## Log the XML Request bodies for debugging
##
#webdav.log-xml = “disable”
auth.backend = “htpasswd”
auth.backend.htpasswd.userfile = “/opt/etc/htpasswd”
auth.require = (“” => (“method” => “basic”,
“realm” => “webdav”,
“require” => “valid-user” ) )
##
##
##
webdav.sqlite-db-name = home_dir + “/webdav.db”
}