Quantcast
Channel: polygun2000的博客
Viewing all articles
Browse latest Browse all 55

用nginx架设webdav服务器

$
0
0
业务部门的新需求,要和国外同事交换文件,原计划使用ftp,但使用sureroute加速有问题,因此改用webdav方式。没啥可说的,流水账记录一下。

1.安装nginx源码包,nginx-dav-ext-module源码
]# useradd builder
]# rpm -ivh http://nginx.org/packages/centos/7/SRPMS/nginx-1.8.1-1.el7.ngx.src.rpm
]# curl -O https://codeload.github.com/arut/nginx-dav-ext-module/zip/master
]# unzip nginx-dav-ext-module-master.zip
]# mv nginx-dav-ext-module-master /root/rpmbuild/BUILD/nginx-dav-ext-module

2.修改nginx的SPEC文件
]# cd /root/rpmbuild/SPECS
]# patch -p0 < nginx-dav-ext.patch

3.创建nginx的rpm包
]# rpmbuild -bb nginx.spec

4.安装新生成的rpm包
]# yum localinstall /root/rpmbuild/RPMS/nginx-1.8.1-1.el7.centos.ngx.x86_64.rpm

5.创建webdav的配置文件
]# vi /etc/nginx/conf.d/webdav.conf 
server {
    listen       8080;
    server_name  localhost;

    #charset koi8-r;
    #access_log  /var/log/nginx/log/host.access.log  main;

    location / {
        root /home/swapzone;
        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  404              /404.html;

    # redirect server error pages to the static page /50x.html
    #
    error_page   500 502 503 504  /50x.html;
    location = /50x.html {
        root   /usr/share/nginx/html;
    }
}

修改最大允许上传得文件大小
]# vi /etc/nginx/nginx.conf
===> client_max_body_size 20G;

6.安装httpd-tools,设置用户认证
]# yum install httpd-tools
]# htpasswd -c /etc/nginx/.htpasswd us_user
]# htpasswd /etc/nginx/.htpasswd en_user

7.删除nginx包中默认配置文件
]# cd /etc/nginx/conf.d/
]# rm -f default.conf example_ssl.conf

8.启动nginx
]# systemctl start nginx
]# systemctl enable nginx

9.安装cyberduck客户端,即可开始使用。

参考文档:
1.http://www.agoragames.com/blog/2009/03/20/webdav-nginx-play-nice/
2.https://github.com/arut/nginx-dav-ext-module/
3.http://www.cnblogs.com/dtrees/archive/2013/02/07/2908833.html
4.https://opensource.ncsa.illinois.edu/confluence/display/ERGO/Creating+a+WebDAV+repository+server+with+NGINX
5.https://letitknow.wordpress.com/2012/02/29/simple-private-cloud-storage-using-webdav/
6.https://www.digitalocean.com/community/tutorials/how-to-configure-webdav-access-with-apache-on-ubuntu-12-04
7.http://moongazer.me/archives/81
8.https://www.digitalocean.com/community/tutorials/how-to-set-up-basic-http-authentication-with-nginx-on-centos-7
9.https://blog.linuxeye.com/333.html


附录: nginx-dav-ext.patch:
]# diff -uN nginx.spec.orig nginx.spec > nginx-dav-ext.patch
--- nginx.spec.orig     2016-03-08 10:52:18.343030724 +0800
+++ nginx.spec  2016-03-08 11:12:37.193607613 +0800
@@ -121,62 +121,17 @@
         --with-http_realip_module \
         --with-http_addition_module \
         --with-http_sub_module \
-        --with-http_dav_module \
-        --with-http_flv_module \
-        --with-http_mp4_module \
+        --with-http_dav_module --add-module=../nginx-dav-ext-module\
         --with-http_gunzip_module \
         --with-http_gzip_static_module \
         --with-http_random_index_module \
         --with-http_secure_link_module \
         --with-http_stub_status_module \
         --with-http_auth_request_module \
-        --with-mail \
-        --with-mail_ssl_module \
         --with-file-aio \
-        --with-ipv6 \
-        --with-debug \
         %{?with_spdy:--with-http_spdy_module} \
         --with-cc-opt="%{optflags} $(pcre-config --cflags)" \
         $*
-make %{?_smp_mflags}
-%{__mv} %{_builddir}/%{name}-%{version}/objs/nginx \
-        %{_builddir}/%{name}-%{version}/objs/nginx.debug
-./configure \
-        --prefix=%{_sysconfdir}/nginx \
-        --sbin-path=%{_sbindir}/nginx \
-        --conf-path=%{_sysconfdir}/nginx/nginx.conf \
-        --error-log-path=%{_localstatedir}/log/nginx/error.log \
-        --http-log-path=%{_localstatedir}/log/nginx/access.log \
-        --pid-path=%{_localstatedir}/run/nginx.pid \
-        --lock-path=%{_localstatedir}/run/nginx.lock \
-        --http-client-body-temp-path=%{_localstatedir}/cache/nginx/client_temp \
-        --http-proxy-temp-path=%{_localstatedir}/cache/nginx/proxy_temp \
-        --http-fastcgi-temp-path=%{_localstatedir}/cache/nginx/fastcgi_temp \
-        --http-uwsgi-temp-path=%{_localstatedir}/cache/nginx/uwsgi_temp \
-        --http-scgi-temp-path=%{_localstatedir}/cache/nginx/scgi_temp \
-        --user=%{nginx_user} \
-        --group=%{nginx_group} \
-        --with-http_ssl_module \
-        --with-http_realip_module \
-        --with-http_addition_module \
-        --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_random_index_module \
-        --with-http_secure_link_module \
-        --with-http_stub_status_module \
-        --with-http_auth_request_module \
-        --with-mail \
-        --with-mail_ssl_module \
-        --with-file-aio \
-        --with-ipv6 \
-        %{?with_spdy:--with-http_spdy_module} \
-        --with-cc-opt="%{optflags} $(pcre-config --cflags)" \
-        $*
-make %{?_smp_mflags}
 
 %install
 %{__rm} -rf $RPM_BUILD_ROOT
@@ -235,9 +190,6 @@
    $RPM_BUILD_ROOT%{_sysconfdir}/logrotate.d/nginx
 %endif
 
-%{__install} -m644 %{_builddir}/%{name}-%{version}/objs/nginx.debug \
-   $RPM_BUILD_ROOT%{_sbindir}/nginx.debug
-
 %clean
 %{__rm} -rf $RPM_BUILD_ROOT
 
@@ -277,12 +229,10 @@
 %attr(0755,root,root) %dir %{_localstatedir}/cache/nginx
 %attr(0755,root,root) %dir %{_localstatedir}/log/nginx
 
-%files debug
-%attr(0755,root,root) %{_sbindir}/nginx.debug
-
 %pre
 # Add the "nginx" user
 getent group %{nginx_group} >/dev/null || groupadd -r %{nginx_group}
+getent group %{nginx_loggroup} >/dev/null || groupadd -r %{nginx_loggroup}
 getent passwd %{nginx_user} >/dev/null || \
     useradd -r -g %{nginx_group} -s /sbin/nologin \
     -d %{nginx_home} -c "nginx user"  %{nginx_user}

 

Viewing all articles
Browse latest Browse all 55

Trending Articles