Nginx webdav ubuntu 20.04

Запись создана 22 апреля, 2022

Если вам по какой-то причине оочень нужен webdav работающий на nginx, поделюсь сценарием установки и конфигами.

Сразу хочу предупредить, подружить удалось с windows MacOS но не получилось с IOS. Лучше используйте Apache или Synology (XPEnology).

apt-get install build-essential libcurl4-openssl-dev libxml2-dev mime-support automake libssl-dev libpcre3-dev zlib1g-dev libxslt1-dev checkinstall pkgconf libperl-dev
 
mkdir nginx
cd nginx/
 
wget https://nginx.org/download/nginx-1.20.2.tar.gz
wget https://github.com/arut/nginx-dav-ext-module/archive/refs/tags/v3.0.0.tar.gz -O nginx-dav-ext-module-v3.0.0.tar.gz
wget https://github.com/aperezdc/ngx-fancyindex/archive/refs/tags/v0.5.2.tar.gz -O ngx-fancyindex-v0.5.2.tar.gz
wget https://github.com/openresty/headers-more-nginx-module/archive/v0.33.tar.gz -O headers-more-nginx-module-v0.33.tar.gz
 
tar zxf headers-more-nginx-module-v0.33.tar.gz
tar zxf nginx-1.20.2.tar.gz
tar zxf nginx-dav-ext-module-v3.0.0.tar.gz
tar zxf ngx-fancyindex-v0.5.2.tar.gz

cd nginx-1.20.2/
 
./configure --prefix=/etc/nginx \
            --sbin-path=/usr/sbin/nginx \
            --modules-path=/usr/lib/nginx/modules \
            --conf-path=/etc/nginx/nginx.conf \
            --error-log-path=/var/log/nginx/error.log \
            --pid-path=/var/run/nginx.pid \
            --lock-path=/var/run/nginx.lock \
            --user=nginx \
            --group=nginx  \
            --build=Ubuntu  \
            --builddir=nginx-1.20.2  \
            --with-select_module  \
            --with-poll_module  \
            --with-threads  \
            --with-file-aio  \
            --with-http_ssl_module  \
            --with-http_v2_module  \
            --with-http_realip_module  \
            --with-http_addition_module  \
            --with-http_xslt_module=dynamic  \
            --with-http_image_filter_module=dynamic  \
            --with-http_geoip_module=dynamic  \
            --with-http_sub_module  \
            --with-http_dav_module  \
            --with-http_flv_module  \
            --with-http_mp4_module  \
            --with-http_gunzip_module \
            --with-http_gzip_static_module  \
            --with-http_auth_request_module \
            --with-http_random_index_module \
            --with-http_secure_link_module \
            --with-http_degradation_module \
            --with-http_slice_module \
            --with-http_stub_status_module \
            --with-http_perl_module=dynamic \
            --with-perl_modules_path=/usr/share/perl/5.30.0 \
            --with-perl=/usr/bin/perl \
            --http-log-path=/var/log/nginx/access.log \
            --http-client-body-temp-path=/var/cache/nginx/client_temp \
            --http-proxy-temp-path=/var/cache/nginx/proxy_temp \
            --http-fastcgi-temp-path=/var/cache/nginx/fastcgi_temp \
            --http-uwsgi-temp-path=/var/cache/nginx/uwsgi_temp \
            --http-scgi-temp-path=/var/cache/nginx/scgi_temp  \
            --with-mail=dynamic \
            --with-mail_ssl_module \
            --with-stream=dynamic \
            --with-stream_ssl_module \
            --with-stream_realip_module \
            --with-stream_geoip_module=dynamic \
            --with-stream_ssl_preread_module \
            --with-compat \
            --with-pcre \
            --with-pcre-jit \
            --with-openssl-opt=no-nextprotoneg \
            --with-debug \
            --add-module=../nginx-dav-ext-module-3.0.0 \
            --add-module=../ngx-fancyindex-0.5.2 \
            --add-module=../headers-more-nginx-module-0.33
 
make -j4
checkinstall
cat > /lib/systemd/system/nginx.service << EOF
[Unit]
Description=The NGINX HTTP and reverse proxy server
After=syslog.target network-online.target remote-fs.target nss-lookup.target
Wants=network-online.target
 
[Service]
Type=forking
PIDFile=/var/run/nginx.pid
ExecStartPre=/usr/sbin/nginx -t
ExecStart=/usr/sbin/nginx
ExecReload=/usr/sbin/nginx -s reload
ExecStop=/bin/kill -s QUIT $MAINPID
PrivateTmp=true
 
[Install]
WantedBy=multi-user.target
EOF
 
 
mkdir "/var/cache/nginx/client_temp" -p
chown -R nginx:nginx /var/cache/nginx/
 
systemctl enable nginx
systemctl start nginx

Конфиг nginx

dav_ext_lock_zone zone=a:10m;
 
server {
    charset UTF-8;
    server_name _;
    listen 80 default_server;
 
 
    location / {
        try_files $uri $uri/ =404;
        root /var/www/;
        location / {
            autoindex on;
        }
        index index.html index.htm;
 
    }
}
 
 
server {
    charset UTF-8;
    server_name cloud.test.ru; # managed by Certbot
    listen 80 ;
 
    set $webdav_root "/store/share";
    dav_ext_lock zone=a;
 
    location / {
        root $webdav_root;
 
        error_page              599 = @propfind_handler;
        error_page              598 = @delete_handler;
        error_page              597 = @copy_move_handler;
 
        autoindex on;
        autoindex_exact_size    on;
        autoindex_localtime     on;
 
        index index.html index.htm;
 
        open_file_cache off;
 
        send_timeout 3600;
        client_body_timeout 3600;
        keepalive_timeout 3600;
        lingering_timeout 3600;
 
        client_max_body_size    10G;
 
        if ($request_method = PROPFIND) {
                return 599;
        }
        if ($request_method = PROPPATCH) { # Unsupported, allways return OK.
                add_header      Content-Type 'text/xml';
                return          207 '<?xml version="1.0"?><a:multistatus xmlns:a="DAV:"><a:response><a:propstat><a:status>HTTP/1.1 200 OK</a:status></a:propstat></a:response></a:multistatus>';
        }
        if ($request_method = MKCOL) { # Microsoft specific handle: add trailing slash.
                rewrite ^(.*[^/])$ $1/ break;
        }
        if ($request_method = OPTIONS) {
                add_header      Allow 'OPTIONS, GET, HEAD, POST, PUT, MKCOL, MOVE, COPY, DELETE, PROPFIND, PROPPATCH, LOCK, UNLOCK';
                add_header      DAV '1, 2';
                return 200;
        }
        if ($request_method = DELETE) {
                return 598;
        }
        if ($request_method = COPY) {
                return 597;
        }
        if ($request_method = MOVE) {
                return 597;
        }
 
        dav_methods     PUT MKCOL;
        dav_ext_methods OPTIONS LOCK UNLOCK;
        create_full_put_path    on;
        min_delete_depth        0;
        dav_access      user:rw group:rw all:rw;
 
 
        auth_basic "Restricted";
        auth_basic_user_file /store/share/.webdav_htpasswd;
    }
 
location @propfind_handler {
        internal;
 
        open_file_cache off;
        if (!-e $webdav_root/$uri) { # Microsoft specific handle.
                return 404;
        }
        root            $webdav_root;
        dav_ext_methods PROPFIND;
}
location @delete_handler {
        internal;
 
        open_file_cache off;
        if (-d $webdav_root/$uri) { # Add trailing slash to dirs.
                rewrite ^(.*[^/])$ $1/ break;
        }
        root            $webdav_root;
        dav_methods     DELETE;
}
location @copy_move_handler {
        internal;
 
        open_file_cache off;
        if (-d $webdav_root/$uri) { # Microsoft specific handle: Add trailing slash to dirs.
                more_set_input_headers 'Destination: $http_destination/';
                rewrite ^(.*[^/])$ $1/ break;
        }
        root                    $webdav_root;
        dav_methods             COPY MOVE;
}
 
 
    listen 443 ssl; # managed by Certbot
    ssl_certificate /etc/letsencrypt/live/cloud.test.ru/fullchain.pem; # managed by Certbot
    ssl_certificate_key /etc/letsencrypt/live/cloud.test.ru/privkey.pem; # managed by Certbot
    include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
    ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot
 
}

задаем пароль пользователя:

 htpasswd -c .webdav_htpasswd share

» Запись из раздела Linux, Nginx, Ubuntu, web server | Комментировать

Комментарии





Ответить