安装nginx-full版本
apt install nginx-full
创建一个WebDAV
根目录,并授予写入权限。例如,您可以使用以下命令创建并授予权限,/var/www/example.com
替换成自己的实际目录路径
mkdir /var/www/example.com
chown www-data:www-data /var/www/example.com
增加nginx的认证,这里用的是用户名密码,user
就是你要登陆的用户名,/etc/nginx/.htpasswd
换成你自己的文件存放路径
sh -c "echo -n 'user:' >> /etc/nginx/.htpasswd"
sh -c "openssl passwd -apr1 >> /etc/nginx/.htpasswd"
编辑修改nginx配置文件,在server
中增加
# webdav配置
# 认证方式
auth_basic "Restricted Content";
# 存放认证用户名、密码文件(确认有对应权限)
auth_basic_user_file /etc/nginx/.htpasswd;
# dav allowed method
dav_methods PUT DELETE MKCOL COPY MOVE;
# Allow current scope perform specified DAV method
dav_ext_methods PROPFIND OPTIONS;
# In this folder, newly created folder or file is to have specified permission. If none is given, default is user:rw. If all or group permission is specified, user could be skipped
dav_access user:rw group:rw all:r;
# Temporary folder
client_body_temp_path /tmp/webdav;
# MAX size of uploaded file, 0 mean unlimited
client_max_body_size 0;
# Allow autocreate folder here if necessary
create_full_put_path on;
完整示范
server {
listen 80;
listen [::]:80;
server_name example.com;
root /var/www/example.com;
index index.html index.htm index.php;
#return 301 https://$server_name$request_uri;
}
server {
listen 443 ssl;
listen [::]:443 ssl;
server_name example.com;
root /var/www/example.com;
index index.html index.htm index.php;
#php
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/run/php/php7.4-fpm.sock;
}
ssl on;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2 TLSv1.3;
ssl_certificate /etc/letsencrypt/live/example.com/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/example.com/privkey.pem;
# webdav配置
# 认证方式
auth_basic "Restricted Content";
# 存放认证用户名、密码文件(确认有对应权限)
auth_basic_user_file /etc/nginx/.htpasswd;
# dav allowed method
dav_methods PUT DELETE MKCOL COPY MOVE;
# Allow current scope perform specified DAV method
dav_ext_methods PROPFIND OPTIONS;
# In this folder, newly created folder or file is to have specified permission. If none is given, default is us>
dav_access user:rw group:rw all:r;
# Temporary folder
client_body_temp_path /tmp/webdav;
# MAX size of uploaded file, 0 mean unlimited
client_max_body_size 0;
# Allow autocreate folder here if necessary
create_full_put_path on;
}
重启Nginx服务
systemctl restart nginx