0


Nginx安装webdav

OMV是基于Debian的Nas系统,由于omv6已经安装nginx,所以可以直接运行以下命令查看支不支持webdav

nginx -v

输出如下:

root@armbian:~# nginx -V
nginx version: nginx/1.18.0
built with OpenSSL 1.1.1n  15 Mar 2022
TLS SNI support enabled
configure arguments: --with-cc-opt='-g -O2 -ffile-prefix-map=/build/nginx-I6LWFq/nginx-1.18.0=. -fstack-protector-strong -Wformat -Werror=format-security -fPIC -Wdate-time -D_FORTIFY_SOURCE=2' --with-ld-opt='-Wl,-z,relro -Wl,-z,now -fPIC'--prefix=/usr/share/nginx --conf-path=/etc/nginx/nginx.conf --http-log-path=/var/log/nginx/access.log --error-log-path=/var/log/nginx/error.log --lock-path=/var/lock/nginx.lock --pid-path=/run/nginx.pid --modules-path=/usr/lib/nginx/modules --http-client-body-temp-path=/var/lib/nginx/body --http-fastcgi-temp-path=/var/lib/nginx/fastcgi --http-proxy-temp-path=/var/lib/nginx/proxy --http-scgi-temp-path=/var/lib/nginx/scgi --http-uwsgi-temp-path=/var/lib/nginx/uwsgi --with-compat --with-debug --with-pcre-jit --with-http_ssl_module --with-http_stub_status_module --with-http_realip_module --with-http_auth_request_module --with-http_v2_module --with-http_dav_module --with-http_slice_module --with-threads --with-http_addition_module --with-http_flv_module --with-http_geoip_module=dynamic --with-http_gunzip_module --with-http_gzip_static_module --with-http_image_filter_module=dynamic --with-http_mp4_module --with-http_perl_module=dynamic --with-http_random_index_module --with-http_secure_link_module --with-http_sub_module --with-http_xslt_module=dynamic --with-mail=dynamic --with-mail_ssl_module --with-stream=dynamic --with-stream_geoip_module=dynamic --with-stream_ssl_module --with-stream_ssl_preread_module --add-dynamic-module=/build/nginx-I6LWFq/nginx-1.18.0/debian/modules/http-headers-more-filter --add-dynamic-module=/build/nginx-I6LWFq/nginx-1.18.0/debian/modules/http-auth-pam --add-dynamic-module=/build/nginx-I6LWFq/nginx-1.18.0/debian/modules/http-cache-purge --add-dynamic-module=/build/nginx-I6LWFq/nginx-1.18.0/debian/modules/http-dav-ext --add-dynamic-module=/build/nginx-I6LWFq/nginx-1.18.0/debian/modules/http-ndk --add-dynamic-module=/build/nginx-I6LWFq/nginx-1.18.0/debian/modules/http-echo --add-dynamic-module=/build/nginx-I6LWFq/nginx-1.18.0/debian/modules/http-fancyindex --add-dynamic-module=/build/nginx-I6LWFq/nginx-1.18.0/debian/modules/http-geoip2 --add-dynamic-module=/build/nginx-I6LWFq/nginx-1.18.0/debian/modules/nchan --add-dynamic-module=/build/nginx-I6LWFq/nginx-1.18.0/debian/modules/http-lua --add-dynamic-module=/build/nginx-I6LWFq/nginx-1.18.0/debian/modules/rtmp --add-dynamic-module=/build/nginx-I6LWFq/nginx-1.18.0/debian/modules/http-uploadprogress --add-dynamic-module=/build/nginx-I6LWFq/nginx-1.18.0/debian/modules/http-upstream-fair --add-dynamic-module=/build/nginx-I6LWFq/nginx-1.18.0/debian/modules/http-subs-filter

检查输出内容中有没–with-http_dav_module和–add-module=/…/nginx-dav-ext-module,有就是表示支持webdav,没有就表示不支持。
PS:由于文字太多了,我把上面输出的内容复制进记事本再ctrl+f查找dav
如果不支持的话,就运行以下代码,安装nginx的扩展模块:

aptinstall nginx-extras -y

PS:如果在没有安装过nginx的Debian中安装,就要运行:

aptinstall nginx nginx-extras -y

或者运行

aptinstall nginx-full -y

创建一个将要用webdav分享(挂载)的目录,如:

mkdir-p /myshare #该目录和路径按自己实际情况去建立

运行如下命令,创建webdav的配置文件

nano /etc/nginx/conf.d/webdav.conf

把以下代码复制进去,

server {
    listen       81;
    server_name  webdav;
    error_log /var/log/nginx/webdav.error.log error;
    access_log  /var/log/nginx/webdav.access.log combined;
    location / {
        root /myshare;
        charset utf-8;
        autoindex on;
        dav_methods PUT DELETE MKCOL COPY MOVE;
        dav_ext_methods PROPFIND OPTIONS;
        create_full_put_path  on;
        dav_access user:rw group:r all:r;
        auth_basic "Authorized Users Only";
        auth_basic_user_file /etc/nginx/.htpasswd;}
    error_page   500502503504  /50x.html;
    location = /50x.html {
        root   /usr/share/nginx/html;}}

注意:
root /myshare指定webdav的分享目录,
listen 81 是访问端口,
/etc/nginx/.htpasswd是账号密码文件,要使用htpasswd -c /etc/nginx/.htpasswd webdav的用户名 来创建一个新的账号密码文件,下面有运行的示例。

设置用户名和密码有两种方法
方法一:
######下面是用apache2-utils工具设置htpasswd用户和密码######

依次按ctrl+o保存和ctrl+x退出nano,这样就建好webdav的配置文件了。
安装apache2-utils,就可以使用htpasswd命令了,运行

apt-getinstall apache2-utils -y

接着运行以下命令,创建.htpasswd账号密码文件

htpasswd -c /etc/nginx/.htpasswd myUserName

输出如下:

root@armbian:~# htpasswd -c /etc/nginx/.htpasswd myUserName
New password:
Re-type new password:
Adding password for user myUserName

注意:要输入两次密码,不显示。

方法二:
###########下面是用each命令创建用户名和密码############
格式:echo 你设置的用户名 😒(openssl passwd 你设置的密码)" >你指定的路径和文件名/.htpasswd
示例:

#在/etc/nginx/下创建用户名为admin密码为123456的文件.htpasswdecho"admin:$(openssl passwd123456)">/etc/nginx/.htpasswd

运行以下命令,重启nginx服务:

systemctl restart nginx.service

关于WebDav的应用:
1、用win10的添加网络位置来访问的体验很不好,不建议这样。
2、建议使用WebDav的客户端来访问,如WinScp,RaiDriver。
3、如果只是想简单下载,那么用浏览器打开:http://你的IP地址:81,然后输入刚才在htpasswd输入的账号和密码就可以了。

标签: linux debian 服务器

本文转载自: https://blog.csdn.net/Abin17618/article/details/132580806
版权归原作者 Abin17618 所有, 如有侵权,请联系我们删除。

“Nginx安装webdav”的评论:

还没有评论