Self Host Webdav Server

  1. Create these files in a new directory
  2. Replace <dir> in docker-compose.yml with your webdav directory
  3. Install Nginx and Docker Compose
  4. Run chmod +x run.sh
  5. Access your webdav server on http://127.0.0.1:9001
docker-compose.yaml
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
version: "3"

services:
  webdav:
    container_name: webdav
    image: micromata/dave:latest
    user: "1000:1000"
    ports:
      - "127.0.0.1:8000:8000"
    volumes:
      - './config.yaml:/config.yaml:ro'
      - '<dir>:/tmp:rw'
nginx.conf
 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
upstream webdav {
    server 127.0.0.1:8000;
    keepalive 32;
}

server {
    listen 9001;
    server_name _;

    client_max_body_size 0;
    location / {
        auth_pam "Restricted";
        auth_pam_service_name "common-auth";

        #rewrite /webdav/(.*) /$1 break;
        proxy_pass http://webdav;

        proxy_buffering off;

        # Keep-alive
        proxy_http_version                 1.1;
        proxy_set_header Connection        "";

        # Proxy headers
        proxy_set_header Host              $host;
        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;
        proxy_set_header X-Forwarded-Host  $host;
        proxy_set_header X-Forwarded-Port  $server_port;

        # Proxy timeouts between successive read/write operations, not the whole request.
        proxy_connect_timeout              300s;
        proxy_send_timeout                 300s;
        proxy_read_timeout                 300s;
    }
}
config.yaml
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
# ---------------------------------- Network -----------------------------------
#
# The bind address to use
#
address: "0.0.0.0"
#
# The listening port
#
port: "8000"
#
# The prefix path of the server. Default none
#
prefix: "/"
# ---------------------------------- Content -----------------------------------
#
# The provided base dir
#
dir: "/tmp"
run.sh
1
2
3
4
5
6
#!/bin/zsh

sudo ln -s $PWD/nginx.conf /etc/nginx/sites-enabled/webdav.conf
docker-compose pull
docker-compose up --build --force-recreate  -d
sudo systemctl restart nginx