使用 Docker 部署 WebDAV 服务并通过 Nginx 反向代理

wpboke1 2024-12-12 208 12/12

1. 使用 Docker 部署 WebDAV 服务

1.1 创建 docker-compose.yml

services:
  webdav:
    image: hacdias/webdav
    container_name: webdav
    restart: always
    ports:
      - 8092:8080
    volumes:
      - ./data:/data
      - ./config.yml:/config.yml

1.2 配置 config.yml

address: 0.0.0.0
port: 8080
auth: true
prefix: /
modify: true
rules: []
 
cors:
  enabled: true
  credentials: true
  allowed_headers:
    - Depth
  allowed_hosts:
    - http://localhost:8080
  allowed_methods:
    - GET
  exposed_headers:
    - Content-Length
    - Content-Range
 
users:
  - username: admin
    password: "{bcrypt}$2a$10$<hashed-password>"
    directory: /data
    permissions: CRUD
    rules:
      - path: /data
        permissions: CRUD

1.3 启动 Docker 容器

docker-compose up -d

2. 配置 Nginx 反向代理

server {
    listen 443 ssl;
    listen [::]:443 ssl;
    server_name webdav.1024.do;
 
    # ssl相关配置
    ssl_certificate /usr/local/nginx/cert/1024.do.pem;
    ssl_certificate_key /usr/local/nginx/cert/1024.do.key;
    ssl_session_timeout 10m;
    ssl_prefer_server_ciphers on;
 
    location / {
        proxy_pass http://localhost:8092;
        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 $host;
        proxy_redirect off;
    }
 
    # 默认拒绝所有非指定域名的请求
    if ($host != "webdav.1024.do") {
        return 403;
    }
}
 
server {
    listen 80;
    listen [::]:80;
    server_name webdav.1024.do;
    rewrite ^/(.*) https://$host$request_uri permanent;
}

2.2 重启 Nginx

systemctl restart nginx
nginx -s reload

3. 测试和访问

总结:

- THE END -

wpboke1

12月12日23:20

最后修改:2024年12月12日
0

非特殊说明,本博所有文章均为博主原创。

共有 0 条评论