3

OpenWRT配置WebDAV的简明教程(基于Lighttpd)

 1 year ago
source link: https://direct5dom.github.io/2023/06/06/OpenWRT%E9%85%8D%E7%BD%AEWebDAV%E7%9A%84%E7%AE%80%E6%98%8E%E6%95%99%E7%A8%8B%EF%BC%88%E5%9F%BA%E4%BA%8ELighttpd%EF%BC%89/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

logo.png

安装相关软件

opkg update
opkg install lighttpd lighttpd-mod-auth lighttpd-mod-authn_file lighttpd-mod-webdav

配置Lighttpd端口号

为什么要这么做?

因为Lighttpd的默认端口号为80,与LuCI的默认端口号冲突。后续启用Lighttpd会导致LuCI无法正常访问(即便WebDAV可以使用)。

修改Lighttpd的配置文件:/etc/lighttpd/lighttpd.conf

在其中添加/修改下行:

server.port = <PORT>

此处的<PORT>为你想要设置的端口号。

配置Lighttpd

此处假设你要共享的目录为:/mnt/disk

# 手动创建所需目录
mkdir -p /etc/lighttpd/conf.d /var/lib/lighttpd

# 为 http:www-data 分配目录访问权限
chown http:www-data /mnt/disk /var/lib/lighttpd

# 向配置文件写入配置(注意,配置中的内容要根据具体情况修改,详见下方说明)
cat << "EOF" > /etc/lighttpd/conf.d/99-disk.conf
$HTTP["url"] =~ "^/disk($|/)" {
server.document-root := "/mnt"
auth.backend = "plain"
auth.backend.plain.userfile = "/etc/lighttpd/webdav.shadow"
auth.require = (
"/disk" => ("method" => "basic", "realm" => "disk", "require" => "valid-user")
)
auth.cache = ("max-age" => "3600")
}
EOF

这里最后一个命令可能需要改动的地方有:

  • 第二行的/mnt,需要改为你要共享的根目录,这里是一般磁盘挂载的目录。
  • 第一行、第六行的disk,需要改为你要共享的子目录。

这里的配置含义是,将/mnt/disk目录通过WebDAV共享,日后可以通过http://<IP>:<PORT>/disk的形式访问。

echo "<youruser>:<somesecret>" > /etc/lighttpd/webdav.shadow

其中<youruser>为用户名,<somesecret>为密码。

**注意:**这个密码未经编码,并以明文形式保存在路由器上(以确保更好的性能)。如果黑客可以访问该文件,它可以看到您的密码。所以不要在这里放置您在其他任何地方使用的密码。

此外,也可以生成一个随机密码:

>< /dev/urandom tr -dc _A-Z-a-z-0-9 | head -c${1:-32}; echo

重启Lighttpd

/etc/init.d/lighttpd restart

WebDAV Share

Lighttpd webserver


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK