需安装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