青

一言

使用 WsgiDAV 在 Windows 设备上搭建 WebDAV 服务

使用 WsgiDAV 在 Windows 设备上搭建 WebDAV 服务

使用 WsgiDAV 在 Windows 设备上搭建 WebDAV 服务

  • WebDAV 是什么?

基于 Web 的分布式编写和版本控制(WebDAV)是超文本传输协议(HTTP)的扩展,有利于用户间协同编辑和管理存储在万维网服务器文档。(Wiki

  • 哪里有 WebDAV?

部分云存储平台(如坚果云),大部分私有云存储(如 Seafile,群晖 NAS)

  • 带有 WebDAV 的常见服务

Wiki:
Apache HTTP Server提供基于davfs和Apache Subversion (svn)的WebDAV模块。
微软的IIS也有WebDAV模块。
Nginx有非常有限的可选WebDav模块和第三方模块
lighttpd有一个可选的WebDav模块

  • WebDAV 有什么用?
    • MacOS 原生支持
    • [Windows Explorer 支持](#Windows 挂载)
    • 部分软件同步(如 Noteability 笔记软件等)
    • [远程音视频(Kodi)](#在 Kodi 上使用)

安装

官方安装文档:传送门

在 Ubuntu 上进行安装

1
2
3
4
apt update
apt install python3-dev python3-pip
pip3 install wsgidav
pip3 install cheroot

在 Windows 上进行安装

<方法一>

  1. 安装 Python

  2. 安装 PIP 库

    pip install wsgidav charoot -i https://mirrors.aliyun.com/pypi/simple

<方法二>
安装官方提供的 MSI 安装包 前往 Github 下载

运行测试

1
wsgidav --host=0.0.0.0 --port=8080 -r=/root/test1 --auth=anonymous

即可访问 http://[IP]:8080 查看 WebDAV 页面

配置

官方配置指南:传送门

  • 直接运行
    如果是在 Windows 临时使用,那么可以直接在需要共享的硬盘下执行

    wsgidav –host=0.0.0.0 –port=19999 –root=/ –auth=nt

即可快速启动一个 WsgiDAV 服务,通过计算机的用户名和密码进行登录

WsgiDAV 运行后会在路径下查找 config.jsonconfig.yaml,如果找到,则从中读取配置,也可在运行参数中指定配置文件或忽略配置文件,详见官方说明。

以 YAML 格式为例,给出详细说明

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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117

server: cheroot

# 配置服务提供程序,默认是 Cheroot (前述通过 pip 进行安装,Windows 的 MSI 安装包中已附带了)
# 其他参数:
# max: -1
# numthreads: 10
# request_queue_size: 5
# shutdown_timeout: 5
# timeout: 10

# 基础配置
host: 0.0.0.0 # 监听的 IP
port: 19999 # 监听的端口
block_size: 8192 # 传输块大小
add_header_MS_Author_Via: true # 为 MS Office 添加的头部数据(默认 true)

# 补丁,请参见官方说明
hotfixes:
emulate_win32_lastmod: false
re_encode_path_info: true
unquote_path_info: false
treat_root_options_as_asterisk: false

# SSL 支持
ssl_certificate: '/wsgidav.pem' # SSL 证书
ssl_private_key: '/wsgidav.key' # SSL 密钥
# ssl_certificate_chain: null # SSL 公钥链
ssl_adapter: 'builtin' # SSL 服务插件,可选 builtin 和 pyopenssl ,默认 builtin

# 中间件,参见官方说明
middleware_stack:
- wsgidav.mw.cors.Cors
- wsgidav.error_printer.ErrorPrinter
- wsgidav.http_authenticator.HTTPAuthenticator
- wsgidav.dir_browser.WsgiDavDirBrowser
- wsgidav.request_resolver.RequestResolver # RequestResolver 必须是最后一个中间件

# 文件共享
mount_path: null # 挂载路径 <mount_path>/<share_name>/<res_path>
provider_mapping: # 地址转换
'/': '/'
'/pub': # 访问路径
root: '/path/to/share2' # 目标路径
readonly: true # 只读

# 身份认证
http_authenticator:
accept_basic: true # Basic 认证
accept_digest: true # Digest 认证
default_to_digest: true # 默认认证方式,true 为 Digest,false 为 Basic
trusted_auth_header: null # 信任的请求头
domain_controller: null # 认证控制模块,与之后的 xx_dc 对应,可选:
# * wsgidav.dc.simple_dc.SimpleDomainController
# * wsgidav.dc.pam_dc.PAMDomainController
# * wsgidav.dc.nt_dc.NTDomainController

simple_dc:
# DC参数
user_mapping:
'*': # 允许访问的资源
'username': # 用户名
password: 'password' # 密码
roles: ['editor'] # 角色
nt_dc:
preset_domain: null
preset_server: null
pam_dc:
service: 'login'
encoding: 'utf-8'
resetcreds: true

# CORS 防护,参见官方说明
cors:
allow_origin: null
allow_methods:
allow_headers:
expose_headers:
allow_credentials: false
max_age: 600
add_always:

# 属性管理器,默认为空,即不使用,配置参见官方说明
property_manager: null
mutable_live_props:
- '{DAV:}getlastmodified'

# 资源锁管理
lock_storage: true # 默认 true 使用 wsgidav.lock_man.lock_storage.LockStorageDict,null 为不使用

# 调试信息
verbose: 3 # 调试信息等级
logging: # 日志信息
logger_date_format: '%H:%M:%S'
logger_format: '%(asctime)s.%(msecs)03d - %(levelname)-8s: %(message)s'
debug_methods: []
debug_litmus: []

# Wsgi 路径管理模块
dir_browser:
enable: true # 允许路径索引
ignore: # 忽略路径
- '.DS_Store'
- 'Thumbs.db'
- '._*'
- 'wsgidav.pem'
- 'wsgidav.key'
icon: false # 显示 WsgiDAV 图标在 Web 页面顶端
response_trailer: true # 页脚信息,true 为默认
show_user: true # 在 Web 页面上显示用户名
show_logout: true # 在 Web 页面上显示 Logout
davmount: true
davmount_links: false
ms_sharepoint_support: true # MS Office 编辑链接
libre_office_support: true # Libre Office 编辑链接
htdocs_path: null

运行

若使用配置文件,在配置文件目录下直接执行

wsgidav

即可启动

Windows 挂载

!!! 虽然可以进行 Basic 认证,若通过公网访问,仍然非常建议使用 SSL 保护连接安全!!!
如果是内网环境使用 HTTP 的话可以参考来自百度的方法:

HKEY_LOCAL_MACHINESYSTEMCurrentControlSetServicesWebClientParameters

把BasicAuthLevel 值改成2,即同时支持http和https,默认只支持https

然后重启服务:

1
2
net stop webclient
net start webclient
  1. 打开 此电脑
  2. 选择 【映射网络驱动器】
  3. 根据提示填写配置
    文件夹内填写 WebDAV 对应的域名端口,如 https://web.tdh6.top:8080/
    选择使用其他凭据连接
    点击完成后在弹出窗口输入用户名密码
  4. 开始使用

在 Kodi 上使用

!!!在 Kodi 上使用 HTTPS 需要配置安全的证书(可能有其他方式可以不进行验证,但我不管 请自行了解) !!!

依次进入 【设置】-【媒体】-【资料库】-【视频】-【添加视频】

在添加视频源处选择【浏览】

选择【添加网络位置】,协议选择 WebDAV 服务器(HTTPS),域名、端口、用户名、密码进行对应填写,点击确定后选择添加好的路径,为源进行命名即可。

本文作者:
本文链接:https://tdh6.top/%E8%BF%90%E7%BB%B4/wsgi-win/
版权声明:本站文章采用 CC BY-NC-SA 3.0 CN 协议进行许可,翻译文章遵循原文协议。
图片来源:本站部分图像来源于网络,前往查看 相关说明。