海运的博客

nginx配置webdav及使用curl测试

发布时间:February 2, 2021 // 分类:Nginx // No Comments

需安装http-dav-ext扩展,有时使用非标准webdav客户端删除目录时最后不带/,nginx删除目录失败返回409,alias不支持rewrite使用root。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
location /webdav/ {
  satisfy any;
  allow 127.0.0.1;
  deny all;
  #root /;
  #if (-d $request_filename) { rewrite ^(.*[^/])$ $1/ break; }
  alias /webdav/;
  dav_methods PUT DELETE MKCOL COPY MOVE;
  dav_ext_methods PROPFIND OPTIONS;
  dav_access user:rw group:r all:r;
  create_full_put_path  on;
  port_in_redirect off;
  autoindex on;
  autoindex_localtime on;
  charset utf-8;
  auth_basic "Login";
  auth_basic_user_file htpasswd;
}

配置nginx webdav不同用户使用不同的家目录:

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
map $remote_user $home {
  default      $remote_user;
  ''           guest;
}
server {
  listen 80 default_server;
  listen [::]:80 default_server;
  server_name _;
 
  root /var/www/html;
  index index.html index.htm index.nginx-debian.html;
 
  try_files $uri /;
 
  location / {
    #if (-d $request_filename) { rewrite ^(.*[^/])$ $1/ break; }
    alias /data/webdav/$home/;
    #dav_methods PUT DELETE MKCOL COPY MOVE;
    dav_ext_methods PROPFIND OPTIONS;
    dav_access user:r group:r all:r;
    create_full_put_path on;
    port_in_redirect off;
    autoindex on;
    autoindex_localtime on;
    charset utf-8;
    auth_basic "Login";
    auth_basic_user_file htpasswd;
  }
 
  #access_log off;
  access_log /var/log/nginx/webdav.log;
  error_log  /var/log/nginx/webdav_error.log;
}

使用curl测试webdav:
新建目录,注意最后一定要带/,不然返回409,MKCOL can create a collection only

1
curl -X MKCOL https://www.haiyun.me/webdav/test/

上传文件:

1
curl -T filename https://www.haiyun.me/webdav/

重命名文件:

1
curl -X MOVE --header 'Destination:https://www.haiyun.me/webdav/newname' https://www.haiyun.me/webdav/filename

删除文件:

1
curl -X DELETE https://www.haiyun.me/webdav/filename

标签:nginx, curl, webdav, curl测试webdav

评论已关闭

分类
最新文章
最近回复
  • rer: 感谢分享!~
  • opnfense: 谢谢博主!!!解决问题了!!!我之前一直以为内置的odhcp6就是唯一管理ipv6的方式
  • liyk: 这个方法获取的IPv6大概20分钟之后就会失效,默认路由先消失,然后Global IPV6再消失
  • 海运: 不好意思,没有。
  • zongboa: 您好,請問一下有immortalwrt設定guest Wi-Fi的GUI教學嗎?感謝您。
  • 海运: 恩山有很多。
  • swsend: 大佬可以分享一下固件吗,谢谢。
  • Jimmy: 方法一 nghtp3步骤需要改成如下才能编译成功: git clone https://git...
  • 海运: 地址格式和udpxy一样,udpxy和msd_lite能用这个就能用。
  • 1: 怎么用 编译后的程序在家里路由器内任意一台设备上运行就可以吗?比如笔记本电脑 m参数是笔记本的...