How to refine nginx webdav for mac OS

In last post, I migrate Navidrome using Nignx. Now, I try to upload new songs to server using WebDav, I find it cannot connect to server. After searching around, I found the solution. This is because the basic nginx in Ubuntu does not contains all function of WebDav. Now, let solve this issue together.

How to refine

Log into your server as root.

1
2
3
apt install nginx-full
apt install libnginx-mod-http-headers-more-filter
vim /etc/nginx/nginx.conf
1
2
3
4
5
#add below in http block for mac OS client lock support. Other setting remains the same, I do not mean to delete all other settings. I just want to make things simpler so other settings are omitted.

http {
dav_ext_lock_zone zone=webdav:10m;
}
1
vim /etc/nginx/sites-available/your.domain
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
server {
listen 80;
server_name your.domain;

# Redirect HTTP to HTTPS
location / {
return 301 https://$host$request_uri;
}
}

server {
listen 443 ssl;
server_name your.domain;

# SSL Configuration
ssl_certificate /etc/letsencrypt/live/your.domain/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/your.domain/privkey.pem;

error_log /var/log/nginx/music_error.log;
access_log /var/log/nginx/music_access.log combined;

# Global character set settings
charset utf-8;

# WebDAV Configuration
location /webdav {
alias /var/www/music;
auth_basic "WebDAV Restricted";
auth_basic_user_file /etc/nginx/.htpasswd;
autoindex on; # Enable Directory Indexing
# Enable full directory creation support. By default, the Put method can only create files in existing directories.
create_full_put_path on;
dav_access user:rw group:rw all:r;
# Add a slash after the URI of various methods to solve the compatibility problem of webdav clients on various platforms
set $dest $http_destination;
if (-d $request_filename) {
rewrite ^(.*[^/])$ $1/;
set $dest $dest/;
}

if ($request_method ~ (MOVE|COPY)) {
more_set_input_headers 'Destination: $dest';
}

if ($request_method ~ MKCOL) {
rewrite ^(.*[^/])$ $1/ break;
}

# Support all methods of WebDav
dav_methods PUT DELETE MKCOL COPY MOVE;
dav_ext_methods PROPFIND OPTIONS LOCK UNLOCK;
dav_ext_lock zone=webdav;

#set the max file size can be uploaded
client_max_body_size 100M;
}

# WebSocket and general proxy support
location / {
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_http_version 1.1;
proxy_set_header Host $host;
proxy_pass http://127.0.0.1:4533;
proxy_read_timeout 600s;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}

# Disable TRACE method
if ($request_method = TRACE) {
return 405;
}
}


1
service nginx restart

Done, happy Linux!

Reference

  1. https://superuser.com/questions/1822050/webdav-mount-on-macos-readonly
  2. https://serverfault.com/questions/1147710/enabling-level-2-webdav-on-nginx
  3. https://blog.csdn.net/lpwmm/article/details/116943643
  4. https://opswill.com/articles/ngnix-full-webdav-server-setup.html