首页 > 解决方案 > nginx webdav 允许对用户进行写访问和对 annoymous 进行读访问

问题描述

我正在尝试在 nginx 中设置一个 webdav 文件夹,只有一个用户可以写入/删除/创建,但匿名用户可以读取。

我的文件夹的 nginx 配置如下所示:

  location /webdav/joe/ {
      client_body_temp_path /tmp;
      dav_methods  PUT DELETE MKCOL COPY MOVE;
      dav_ext_methods PROPFIND OPTIONS;
      limit_except GET PROPFIND OPTIONS { }
      create_full_put_path  on;
      dav_access    user:rw group:rw all:r;

      fancyindex    on;
      fancyindex_exact_size off;
      auth_basic "Restricted Access";
      auth_basic_user_file /etc/nginx/auth/joe;
     }

以上正确限制了对 joe 的访问(joe 是其中包含用户 joe 的 httppasswd 文件)。但不能通过http,给出密码提示,所以只适用于joe。

标签: nginxwebdav

解决方案


我终于通过这样做得到了这个工作:

    location /webdav/joe/ {
            client_body_temp_path /tmp;

            dav_methods  PUT DELETE MKCOL COPY MOVE;
            dav_ext_methods PROPFIND OPTIONS;
            dav_access    user:rw group:rw all:r;
            create_full_put_path  on;
            client_max_body_size 100M;

            limit_except GET PROPFIND OPTIONS HEAD {
              auth_basic "Restricted Access";
              auth_basic_user_file /etc/nginx/auth/joe;
           }

            fancyindex    on;
            fancyindex_exact_size off;
    }

推荐阅读