{"id":28,"date":"2021-05-13T16:13:02","date_gmt":"2021-05-13T16:13:02","guid":{"rendered":"https:\/\/her01n.com\/?p=28"},"modified":"2021-05-13T16:13:02","modified_gmt":"2021-05-13T16:13:02","slug":"webdav-server-with-nginx","status":"publish","type":"post","link":"https:\/\/her01n.com\/?p=28","title":{"rendered":"WebDAV server with nginx"},"content":{"rendered":"\n<h3 class=\"wp-block-heading\"> and how to connect GNOME and Windows 10 client.<\/h3>\n\n\n\n<div class=\"wp-block-columns alignwide is-layout-flex wp-container-core-columns-is-layout-28f84493 wp-block-columns-is-layout-flex\">\n<div class=\"wp-block-column is-layout-flow wp-block-column-is-layout-flow\" style=\"flex-basis:100%\">\n<p class=\"has-text-align-left\"> <a href=\"http:\/\/WebDAV\">WebDAV<\/a> is a protocol for remote file-system access. It is widely supported across operating systems, for example it works out of the box on Windows 10 as well on Gnome.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Configure nginx<\/h2>\n\n\n\n<p>The protocol is based on HTTP and is supported by nginx. The configuration is not simple however.<\/p>\n\n\n\n<p>Make a directory where the shared file system would reside. Make it writable by nginx user, so the users can upload files.<\/p>\n<\/div>\n<\/div>\n\n\n\n<div class=\"wp-block-columns alignwide is-layout-flex wp-container-core-columns-is-layout-28f84493 wp-block-columns-is-layout-flex\">\n<div class=\"wp-block-column is-layout-flow wp-block-column-is-layout-flow\" style=\"flex-basis:100%\">\n<pre class=\"wp-block-code\"><code>$ sudo mkdir \/var\/www\/webdav.mashnp.sk\n$ sudo chown www-data:www-data \/var\/www\/webdav.mashnp.sk<\/code><\/pre>\n\n\n\n<p>Add some user for authentication. <code>htpasswd<\/code> would prompt for the password.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>$ sudo touch \/etc\/nginx\/webdav.mashnp.sk.passwd \n$ sudo htpasswd \/etc\/nginx\/webdav.mashnp.sk.passwd \"username\"<\/code><\/pre>\n\n\n\n<p>Create a virtual server configuration in file <code>\/etc\/nginx\/sites-enabled\/webdav.mashnp.sk<\/code>:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>dav_ext_lock_zone zone=a:10m;\n\nserver { \n  server_name webdav.mashnp.sk; \n  set $webdav_root \"\/var\/www\/webdav.mashnp.sk\";\n  auth_basic \"\u00dalo\u017eisko MASHNP\";\n  auth_basic_user_file \/etc\/nginx\/webdav.mashnp.sk.passwd;\n  dav_ext_lock zone=a;\n\n  location \/ {\n\n\troot\t\t\t$webdav_root;\n\terror_page\t\t599 = @propfind_handler;\n\terror_page\t\t598 = @delete_handler;\n\terror_page\t\t597 = @copy_move_handler;\n\topen_file_cache\t\toff;\n   send_timeout 3600;\n   client_body_timeout 3600;\n   keepalive_timeout 3600;\n   lingering_timeout 3600;\n\tclient_max_body_size\t10G;\n\n\tif ($request_method = PROPFIND) {\n\t\treturn 599;\n\t}\n\tif ($request_method = PROPPATCH) { # Unsupported, allways return OK.\n\t\tadd_header\tContent-Type 'text\/xml';\n\t\treturn\t\t207 '&lt;?xml version=\"1.0\"?&gt;&lt;a:multistatus xmlns:a=\"DAV:\"&gt;&lt;a:response&gt;&lt;a:propstat&gt;&lt;a:status&gt;HTTP\/1.1 200 OK&lt;\/a:status&gt;&lt;\/a:propstat&gt;&lt;\/a:response&gt;&lt;\/a:multistatus&gt;';\n\t}\n\tif ($request_method = MKCOL) { # Microsoft specific handle: add trailing slash.\n\t\trewrite ^(.*&#91;^\/])$ $1\/ break;\n\t}\n\tif ($request_method = DELETE) {\n\t\treturn 598;\n\t}\n\tif ($request_method = COPY) {\n\t\treturn 597;\n\t}\n\tif ($request_method = MOVE) {\n\t\treturn 597;\n\t}\n\n\tdav_methods\t\tPUT MKCOL;\n\tdav_ext_methods\t\tOPTIONS LOCK UNLOCK;\n\tcreate_full_put_path\ton;\n\tmin_delete_depth\t0;\n\tdav_access\t\tuser:rw group:rw all:rw;\n\n\tautoindex\t\ton;\n\tautoindex_exact_size\ton;\n\tautoindex_localtime\ton;\n\tif ($request_method = OPTIONS) {\n\t\tadd_header\tAllow 'OPTIONS, GET, HEAD, POST, PUT, MKCOL, MOVE, COPY, DELETE, PROPFIND, PROPPATCH, LOCK, UNLOCK';\n\t\tadd_header\tDAV '1, 2';\n\t\treturn 200;\n\t}\n}\nlocation @propfind_handler {\n\tinternal;\n\n\topen_file_cache\toff;\n\tif (!-e $webdav_root\/$uri) { # Microsoft specific handle.\n\t\treturn 404;\n\t}\n\troot\t\t\t$webdav_root;\n\tdav_ext_methods\t\tPROPFIND;\n}\nlocation @delete_handler {\n\tinternal;\n\n\topen_file_cache\toff;\n\tif (-d $webdav_root\/$uri) { # Microsoft specific handle: Add trailing slash to dirs.\n\t\trewrite ^(.*&#91;^\/])$ $1\/ break;\n\t}\n\troot\t\t\t$webdav_root;\n\tdav_methods\t\tDELETE;\n}\nlocation @copy_move_handler {\n\tinternal;\n\n\topen_file_cache\toff;\n\tif (-d $webdav_root\/$uri) { # Microsoft specific handle: Add trailing slash to dirs.\n\t\tmore_set_input_headers 'Destination: $http_destination\/';\n\t\trewrite ^(.*&#91;^\/])$ $1\/ break;\n\t}\n\troot\t\t\t$webdav_root;\n\tdav_methods\t\tCOPY MOVE;\n}<\/code><\/pre>\n\n\n\n<p>Restart nginx and obtain the certificate.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>$ sudo nginx -t\n$ sudo systemctl restart nginx\n$ sudo certbot --nginx --redirect -d webdav.mashnp.sk <\/code><\/pre>\n\n\n\n<p>Note that you will not be able to connect with windows 10 client if you use plain http with basic authentication.<\/p>\n\n\n\n<p>Now you should have a running webdav server. You can test with creating a text file in the webdav directory and then visiting <code>https:\/\/webdav.mashnp.sk<\/code> with your browser.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Connect with GNOME<\/h2>\n\n\n\n<ul class=\"wp-block-list\"><li>Open &#8216;Files&#8217;.<\/li><li>Click &#8216;Other Locations&#8217;.<\/li><li>In the field labeled &#8216;Connect to Server&#8217;, type address davs:\/\/webdav.mashnp.sk.<br>Note address with https protocol does not work.<\/li><li>Click connect<\/li><li>Type in authentication, choose to &#8216;Remember forever&#8217;.<\/li><li>Right click the connection label in the side panel, select &#8216;Add bookmark&#8217;.<\/li><\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">Connect with Windows<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\">Map a drive<\/h3>\n\n\n\n<p>Persistent mapping of a network drive is broken, the drive would not reconnect at startup. This is a known windows limitation for webdav drives with basic or digest authorization, see the <a href=\"https:\/\/docs.microsoft.com\/en-us\/troubleshoot\/windows-client\/networking\/cannot-automatically-reconnect-dav-share\">explanation<\/a>.<\/p>\n\n\n\n<p>To work-around, we can create a startup script that would reconnect the drive at startup.<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>Open file explorer, type <code>shell:startup<\/code> to the address bar.<\/li><li>Create a new text document, enter the text:<\/li><\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code>net use M: https:\/\/webdav.mashnp.sk \/savecred \/persistent:no<\/code><\/pre>\n\n\n\n<ul class=\"wp-block-list\"><li>Save the file as <code>map-network-drive.bat<\/code> in the startup folder.<\/li><li>Execute the file by double clicking on it. Enter the credentials.<br>Possibly the credentials would not be required if you have connected the drive before.<\/li><li>It is necessary to mount the drive for every user on the system individually.<\/li><\/ul>\n\n\n\n<h3 class=\"wp-block-heading\">Fix the security warning<\/h3>\n\n\n\n<p>When you drag and drop a file from the shared drive to your local computer,<br>a warning is displayed saying the files may be harmful.<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>Open control panel, network and internet, internet options.<\/li><li>Select security tab, click local intranet icon, click sites button.<\/li><li>Click advanced button.<\/li><li>Type<code> file:\/\/\/M:\/<\/code>, click Add.<\/li><li>Type <code>https:\/\/webdav.mashnp.sk\/<\/code>, click Add.<\/li><li>Click close button, ok button.<\/li><\/ul>\n\n\n\n<h3 class=\"wp-block-heading\">Fix the maximum file size<\/h3>\n\n\n\n<p>By default, the maximum file size to copy is about 50M. When you attempt to copy a larger file you get an error:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>0x80070DF: The file size exceeds the limit allowed and cannot be saved.<\/code><\/pre>\n\n\n\n<p>To fix it:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>Open registry editor.<\/li><li>Locate <code>HKEY_LOCAL_MACHINE\\SYSTEM\\CurrentControlSet\\Services\\WebClient\\Parameters<\/code><\/li><li>Set the parameter <code>FileSizeLimitInBytes<\/code> to <code>4294967295<\/code> in decimal.<\/li><li>Reboot.<\/li><\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">Open points<\/h2>\n\n\n\n<ul class=\"wp-block-list\"><li>The progress is not displayed when copying a big file.<\/li><li>Free disk space displayed is incorrect. Disk space of <code>C:<\/code> drive is shown instead.<\/li><\/ul>\n<\/div>\n<\/div>\n\n\n\n<div class=\"wp-block-group is-layout-flow wp-block-group-is-layout-flow\"><\/div>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>and how to connect GNOME and Windows 10 client. WebDAV is a protocol for remote file-system access. It is widely supported across operating systems, for example it works out of the box on Windows 10 as well on Gnome. Configure nginx The protocol is based on HTTP and is supported by nginx. The configuration is [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-28","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/her01n.com\/index.php?rest_route=\/wp\/v2\/posts\/28","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/her01n.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/her01n.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/her01n.com\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/her01n.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=28"}],"version-history":[{"count":0,"href":"https:\/\/her01n.com\/index.php?rest_route=\/wp\/v2\/posts\/28\/revisions"}],"wp:attachment":[{"href":"https:\/\/her01n.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=28"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/her01n.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=28"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/her01n.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=28"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}