Featured image of post Nginx搭建webdav服务器

Nginx搭建webdav服务器

nginx 搭建 webdav 服务器

certbot通过Cloudflare-api验证申请ssl证书

下面将以【example.com】域名为例

部署 nginx webdav 服务器

1、安装 nginx-full

通过nginx搭建webdav服务需要安装http_dav_module模块。nginx-full版本中直接包含了http_dav_module模块。

1
sudo apt update && sudo apt install nginx-full -y

2 、设置权限

1
sudo chown -R www-data:www-data /mnt && sudo chmod -R 755 /mnt

3 、创建用户登录验证信息(用户名-密码,自行修改)

1
2
## 用户名:admin 密码:123456
rm /etc/webdav/.credentials.list && sudo mkdir -p /etc/webdav && touch /etc/webdav/.credentials.list && echo -n 'admin:' | sudo tee -a /etc/webdav/.credentials.list && sudo openssl passwd -apr1 123456 | sudo tee -a /etc/webdav/.credentials.list

4 、创建 webdav 配置文件

webdav 公网地址: https://webdav.example.com:666

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
mkdir -pm 755 /etc/nginx/conf.d && touch /etc/nginx/conf.d/webdav.conf && chmod u+x /etc/nginx/conf.d/webdav.conf && cat > /etc/nginx/conf.d/webdav.conf <<'EOF'
server {

    # 监听666端口
    listen 666 ssl;

    # 替换为你的域名
    server_name webdav.example.com;

    # 指定 SSL 证书文件和私钥文件的路径
    ssl_certificate /etc/nginx/keyfile/cert.pem;  
    ssl_certificate_key /etc/nginx/keyfile/key.pem;  

    # 设置支持的SSL协议版本
    ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
    # 启用服务器端加密套件优先
    ssl_prefer_server_ciphers on;
    # 设置加密套件,优先用高强度加密算法,并排除匿名加密套件和MD5散列算法
    ssl_ciphers HIGH:!aNULL:!MD5;

	 # 设置使用utf-8编码,防止中文文件名乱码
    charset utf-8;

	 # 这个不加上不显示列表
    autoindex on;

	 # 默认存放文件的路径
	root /mnt;
    
    # 认证方式
    auth_basic              realm_name;

    # 用户密码文件存放位置
    auth_basic_user_file    /etc/webdav/.credentials.list;

    # dav 允许的操作
    dav_methods     PUT DELETE MKCOL COPY MOVE;
    dav_ext_methods PROPFIND OPTIONS;

    # 创建文件的默认权限
    dav_access      user:rw group:rw all:r;

    # 临时文件位置
    client_body_temp_path   /tmp;

    # 最大上传文件限制, 0表示无限制
    client_max_body_size    0;

    # 允许自动创建文件夹(如果有需要的话)
    create_full_put_path    on;
}
EOF

## 重启 nginx
sudo systemctl restart nginx

nginx 维护命令

1 、查看nginx状态

1
sudo systemctl status nginx

2 、升级 nginx-full

1
sudo apt update && sudo apt upgrade nginx-full -y

手机 app 登陆(ES文件浏览器)

可以搭配frp等内网穿透工具将本地webdav服务暴露,这样就可以将本地主机当做网盘来使用。
手机客户端可使用ES文件浏览器,使用效果良好。
玩法挺多,慢慢探究

最后更新于 2025-02-22
本博客已稳定运行 小时 分钟
共发表 112 篇文章 · 总计 109.83 k 字
本站总访问量