Bboysoul's Blog

首页 公告 RSS

nginx搭建webdav服务器

December 15, 2022 本文有 476 个字 需要花费 1 分钟阅读

简介

因为oracle的服务器被墙了,所以一直找不到什么方式可以方便去下载服务器上的备份,想了一下,直接搭建一个webdav吧,通过cloudflare代理下,挂载在nas上就好了。

操作

原先服务器是有一个nginx的,所以正好趁这个机会去编译升级下。

查看原先的编译参数

nginx -V

下载最新的nginx

wget https://nginx.org/download/nginx-1.22.1.tar.gz

tar -zxvf nginx-1.22.1.tar.gz

默认nginx的webdav是不支持PROPFIND这个http请求方法的,所以还需要

git clone https://github.com/arut/nginx-dav-ext-module

之后编译

./configure --prefix=/data/nginx/nginx --with-stream && \
--with-http_ssl_module --with-http_stub_status_module --add-module=/data/nginx/nginx-src/nginx-module-vts && \
--with-http_realip_module --with-http_v2_module --add-module=/data/nginx/nginx-src/ngx_brotli --with-http_auth_request_module && \
--with-http_dav_module --add-module=/data/nginx/nginx-src/nginx-dav-ext-module

这两个参数是最新加的

--with-http_dav_module --add-module=/data/nginx/nginx-src/nginx-dav-ext-module

安装编译环境

apt install gcc libpcre2-dev zlib1g-dev libxslt-dev make libssl-dev -y

之后直接编译就好了

make -j 4

接着配置nginx

server {
    listen       443 ssl http2;
    server_name  dav.xxx.cn;
    ssl_certificate cert/cloudflare/cloudflare.pem;
    ssl_certificate_key cert/cloudflare/cloudflare.key;
    ssl_session_timeout 5m;
    ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE:ECDH:AES:HIGH:!NULL:!aNULL:!MD5:!ADH:!RC4;
    #表示使用的加密套件的类型。
    ssl_protocols TLSv1 TLSv1.1 TLSv1.2; #表示使用的TLS协议的类型。
    ssl_prefer_server_ciphers on;

    location / {
      root   /backup/data/;
      auth_basic_user_file /data/nginx/nginx/conf/auth;
      auth_basic "Please input  password";
      autoindex on;
      proxy_set_header Host       $host;
      proxy_set_header X-Real-IP  $remote_addr;
      access_log logs/webdav.log main;
      dav_methods PUT DELETE MKCOL COPY MOVE;
      create_full_put_path  on;
      dav_access            group:rw  all:rw;
      dav_ext_methods PROPFIND OPTIONS;
    }
}

上面配置中下面的参数比较重要

      dav_methods PUT DELETE MKCOL COPY MOVE;
      create_full_put_path  on;
      dav_access            group:rw  all:rw;
      dav_ext_methods PROPFIND OPTIONS;

还有为了安全,最好加个http basic auth

htpasswd auth bboysoul

      auth_basic_user_file /data/nginx/nginx/conf/auth;
      auth_basic "Please input B1 password";

还有记得

autoindex on;

最后

如果你不想挂载载服务器上,可以直接使用wget -m效果和rsync差不多

欢迎关注我的博客www.bboy.app

Have Fun


Tags:

本站总访问量 本站总访客数