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 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172
| server { listen 80; listen [::]:80; server_name _; set $destination $http_destination; set $new_path ""; set $webdav_root "/path/to/your/folder"; set $checkPropfind ""; location / { root $webdav_root; open_file_cache off; auth_basic "WebDAV"; auth_basic_user_file /etc/nginx/webdav.htpasswd; dav_ext_lock zone=foo; dav_methods PUT DELETE MKCOL COPY MOVE; dav_ext_methods PROPFIND OPTIONS LOCK UNLOCK; autoindex on; autoindex_exact_size on; autoindex_localtime on; error_page 599 = @propfind_handler; error_page 598 = @delete_handler; error_page 597 = @copy_move_handler; error_page 596 = @propfind_withdepth_handler; if ($request_method != OPTIONS) { add_header 'Access-Control-Allow-Origin' '*' always; add_header 'Access-Control-Allow-Credentials' 'true' always; add_header 'Access-Control-Allow-Methods' 'OPTIONS, GET, HEAD, POST, PUT, MKCOL, MOVE, COPY, DELETE, PROPFIND, PROPPATCH, LOCK, UNLOCK' always; add_header 'Access-Control-Allow-Headers' 'Authorization,DNT,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,X-Accept-Charset,X-Accept,origin,accept,if-match,destination,overwrite' always; add_header 'Access-Control-Expose-Headers' 'ETag' always; add_header 'Access-Control-Max-Age' 1728000 always; } if ($request_method = OPTIONS) { add_header 'Content-Type' 'text/plain charset=UTF-8'; add_header 'Access-Control-Allow-Origin' '*'; add_header 'Access-Control-Allow-Credentials' 'true'; add_header 'Access-Control-Allow-Methods' 'OPTIONS, GET, HEAD, POST, PUT, MKCOL, MOVE, COPY, DELETE, PROPFIND, PROPPATCH, LOCK, UNLOCK'; add_header 'Access-Control-Allow-Headers' 'Authorization,DNT,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,X-Accept-Charset,X-Accept,origin,accept,if-match,destination,overwrite'; add_header 'Access-Control-Expose-Headers' 'ETag'; add_header 'Access-Control-Max-Age' 1728000; add_header Allow 'OPTIONS, GET, HEAD, POST, PUT, MKCOL, MOVE, COPY, DELETE, PROPFIND, PROPPATCH, LOCK, UNLOCK'; add_header DAV '1, 2'; return 200; } if ($request_method = PROPFIND) { set $checkPropfind "propfind"; } if ($http_depth = 0) { set $checkPropfind "${checkPropfind}+withDepth"; } if ($http_depth = 1) { set $checkPropfind "${checkPropfind}+withDepth"; } if ($checkPropfind = "propfind") { return 599; } if ($checkPropfind = "propfind+withDepth") { return 596; } if ($request_method = PROPPATCH) { add_header Content-Type 'text/xml'; return 207 '<?xml version="1.0"?><a:multistatus xmlns:a="DAV:"><a:response><a:propstat><a:status>HTTP/1.1 200 OK</a:status></a:propstat></a:response></a:multistatus>'; } if ($request_method = MKCOL) { rewrite ^(?<captured_path>.*[^/])$ $captured_path/ break; } if ($request_method = DELETE) { return 598; } if ($request_method = COPY) { return 597; } if ($request_method = MOVE) { return 597; } } location ~ \.(_.*|DS_Store|Spotlight-V100|TemporaryItems|Trashes|hidden|localized)$ { access_log off; error_log off; if ($request_method = PUT) { return 403; } return 404; } location ~ \.metadata_never_index$ { return 200 "Don't index this drive, Finder!"; } location @propfind_handler { internal; open_file_cache off; if (!-e $webdav_root/$uri) { return 404; } root $webdav_root; dav_ext_methods PROPFIND; } location @propfind_withdepth_handler { auth_basic "WebDAV"; auth_basic_user_file /etc/nginx/webdav.htpasswd; internal; open_file_cache off; if (!-e $webdav_root/$uri) { return 404; } root $webdav_root; dav_ext_methods PROPFIND; } location @delete_handler { auth_basic "WebDAV"; auth_basic_user_file /etc/nginx/webdav.htpasswd; internal; open_file_cache off; if ($destination ~ ^https?://(?<captured_path>.*)$) { set $new_path $captured_path; more_set_input_headers "Destination: http://$new_path"; } if (-d $webdav_root/$uri) { more_set_input_headers "Destination: http://$new_path/"; rewrite ^(?<captured_path>.*[^/])$ $captured_path/ break; } root $webdav_root; dav_methods DELETE; } location @copy_move_handler { auth_basic "WebDAV"; auth_basic_user_file /etc/nginx/webdav.htpasswd; internal; open_file_cache off; if ($destination ~ ^https?://(?<captured_path>.*)$) { set $new_path $captured_path; more_set_input_headers "Destination: http://$new_path"; } if (-d $webdav_root/$uri) { more_set_input_headers "Destination: http://$new_path/"; rewrite ^(?<captured_path>.*[^/])$ $captured_path/ break; } root $webdav_root; dav_methods COPY MOVE; } }
|