WebDav
介绍
WebDav
(WebDistributedAuthoringandVersioning
)是一种基于HTTP
协议的文件系统协议,它允许用户通过Web
浏览器或客户端应用程序访问和管理(上传、下载、编辑和版本控制等)远程文件系统。
WebDav
服务端部署
环境准备
出于访问方便,在云服务器上搭建,资源如下:
阿里云服务器:2c,2g,50g
操作系统:centos7.9
源码安装nginx
需要使用nginx
编译安装方式启用nginx-dav-ext-module
- 安装依赖包
yum install gcc zlib zlib-devel pcre-devel libxml2 libxml2-devel libxslt libxslt-devel openssl openssl-devel -y
每个环境不一样,提示缺什么依赖就安装什么依赖。
- 下载
nginx
和nginx-dav-ext-module
# 下载nginx
wget1 https://github.com/nginx/nginx/archive/refs/tags/release-1.26.3.tar.gz
# 解压nginx
tar xvf release-1.26.3.tar.gz
# 切换到nginx目录,下载nginx-dav-ext-module
cd nginx-release-1.26.3/
wget1 https://github.com/arut/nginx-dav-ext-module/archive/refs/tags/v3.0.0.tar.gz
# 解压nginx-dav-ext-module
tar -xvf v3.0.0.tar.gz
- 编辑安装
nginx
,并指定nginx-dav-ext-module
auto/configure --prefix=/etc/nginx \
--conf-path=/etc/nginx/nginx.conf \
--sbin-path=/usr/sbin/nginx \
--pid-path=/var/run/nginx.pid \
--lock-path=/var/run/nginx.lock \
--error-log-path=/var/log/nginx/error.log \
--http-log-path=/var/log/nginx/access.log \
--with-stream --with-http\_dav\_module --with-http\_ssl\_module --with-http\_v2\_module \
--add-module=./nginx-dav-ext-module-3.0.0
此步骤执行完毕应如:
Configuration summary
+ using system PCRE library
+ using system OpenSSL library
+ using system zlib library
nginx path prefix: "/etc/nginx"
nginx binary file: "/usr/sbin/nginx"
nginx modules path: "/etc/nginx/modules"
nginx configuration prefix: "/etc/nginx"
nginx configuration file: "/etc/nginx/nginx.conf"
nginx pid file: "/var/run/nginx.pid"
nginx error log file: "/var/log/nginx/error.log"
nginx http access log file: "/var/log/nginx/access.log"
nginx http client request body temporary files: "client\_body\_temp"
nginx http proxy temporary files: "proxy\_temp"
nginx http fastcgi temporary files: "fastcgi\_temp"
nginx http uwsgi temporary files: "uwsgi\_temp"
nginx http scgi temporary files: "scgi\_temp"
- 完成剩余编译步骤
make && make install
- 验证
nginx
nginx -V
配置nginx
服务
执行vim /lib/systemd/system/nginx.service
,在文件中添加下面配置项:
[Unit]
Description=A high performance web server and a reverse proxy server
Documentation=man:nginx(8)
After=network.target nss-lookup.target
[Service]
Type=forking
PIDFile=/run/nginx.pid
ExecStartPre=/usr/sbin/nginx -t -q -g 'daemon on; master\_process on;'
ExecStart=/usr/sbin/nginx -g 'daemon on; master\_process on;'
ExecReload=/usr/sbin/nginx -g 'daemon on; master\_process on;' -s reload
ExecStop=-/sbin/start-stop-daemon --quiet --stop --retry QUIT/5 --pidfile /run/nginx.pid
TimeoutStopSec=5
KillMode=mixed
[Install]
WantedBy=multi-user.target
设置nginx
服务
# 重加载systemd配置
systemctl daemon-reload
# 将nginx服务器设置为开机启动项
systemctl enable nginx.service
# 启动nginx
systemctl start nginx.service
# 查看nginx
systemctl status nginx.service
配置WebDav
执行vim /etc/nginx/nginx.conf
,修改内容如下:
server {
listen 8089;
listen [::]:8089;
server\_name localhost;
# 认证方式
auth\_basic realm\_name;
# 存放认证用户名、密码文件
auth\_basic\_user\_file /etc/nginx/.webdav/auth.list;
# webdav服务访问的根目录
root /cherry\_data;
dav\_methods PUT DELETE MKCOL COPY MOVE;
dav\_ext\_methods PROPFIND OPTIONS LOCK UNLOCK;
dav\_access user:rw group:rw all:r;
client\_body\_temp\_path /tmp/webdav;
client\_max\_body\_size 0;
create\_full\_put\_path on;
#添加索引指令,如果忘记这项配置,nginx访问会提示403
location /{
root /cherry\_data;
autoindex on;
autoindex\_format html;
autoindex\_exact\_size off;
autoindex\_localtime on;
charset utf-8,gbk;
}
}
修改nginx.conf
后,验证配置文件语法是否正确:
nginx -t
输出内容如下:
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
表示语法正确,最后执行:
nginx -s reload
重新加载nginx.conf
文件。
添加WebDav
用户
cd /etc/nginx/
mkdir .webdav
cd .webdav/
# 设置用户名为admin
echo -n 'admin:' | tee -a auth.list
openssl passwd -apr1 | tee -a auth.list
Password: #首次输入
Verifying - Password: #再次输入
此用户是用于客户端登陆WebDav
时使用的,请记住,如果忘记了,先将auth.list
置空,然后,重新设置即可。
创建数据目录并赋权
在nginx.conf中,设置了一个数据保存目录,需要创建并赋权:
mkdir /cherry\_data
chmod 777 /cherry\_data
验证WebDav
服务
在浏览器中输入WebDav服务地址:端口号
,然后输入配置的用户名和密码:如此,
WebDav
服务就算搭建完毕了
WebDav搭建问题
问题1
在编译安装时,实际已经存在C
编译器,仍提示没有C
编译器:
checking for OS
+ Linux 3.10.0-1160.119.1.el7.x86\_64 x86\_64
checking for C compiler ... not found
auto/configure: error: C compiler cc is not found
最后,尝试重新安装编译器后成功完成编译:
yum reinstall -y gcc
问题2
采用nginx
搭建的WebDav
服务,通过浏览器不能进行文件拖放,只能用于一些客户端进行数据备份,如Cherry Studio
。