下载WebDAV

wget https://github.com/hacdias/webdav/releases/download/v4.1.1/linux-amd64-webdav.tar.gz && tar -xvzf linux-amd64-webdav.tar.gz && rm -rf LICENSE README.md && mv webdav /usr/bin/webdav && rm -rf linux-amd64-webdav.tar.gz

配置文件

cat > /root/webdav.yaml <<‘EOF’
# 如果用nginx可以127.0.0.1
address: 0.0.0.0
port: 8888
auth: true
tls: false
cert: cert.pem
key: key.pem
prefix: /

scope: .
modify: true
rules: []

cors:
enabled: true
credentials: true
allowed_headers:
– Depth
allowed_hosts:
– http://localhost:8888
allowed_methods:
– GET
exposed_headers:
– Content-Length
– Content-Range
# 用户、密码、目录
users:
– username: admin
password: admin
scope: /joplin/webdav/
EOF

写Systemd 自启

cat > /etc/systemd/system/webdav.service <<‘EOF’
[Unit]
Description=WebDAV server
After=network.target

[Service]
Type=simple
User=root
ExecStart=/usr/bin/webdav –config /root/webdav.yaml
Restart=on-failure

[Install]
WantedBy=multi-user.target
EOF

nginx的反代配置

location / {
proxy_pass http://127.0.0.1:8888;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header REMOTE-HOST $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_redirect off;
}