广告

本站里的文章大部分经过自行整理与测试

2017年1月20日星期五

Linux - Nginx - WebDAV 服务

1. 准备

$ su

$ mkdir /var/webdav
$ chmod 777 /var/webdav

$ printf "USER:$(openssl passwd -crypt PASSWORD)\n" >> /var/.htpasswd

$ printf "USER:Y/RasqlW9biwY\n" >> /var/.htpasswd

2. 下载 / 解压 / 安装

Ubuntu
http://jasonmun.blogspot.my/2017/01/ubuntu-nginx-webdav.html

Fedora
$ dnf install gcc gcc-c++ git make expat-devel

CentOS
$ yum install gcc gcc-c++ git make expat-devel

OpenSUSE
$ zypper install gcc gcc-c++ git make libexpat-devel

$ cd /home/username/Downloads

下载
$ wget ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.40.tar.gz
$ wget http://zlib.net/zlib-1.2.11.tar.gz
$ wget https://www.openssl.org/source/openssl-1.1.0c.tar.gz
$ wget http://nginx.org/download/nginx-1.11.8.tar.gz
$ git clone https://github.com/arut/nginx-dav-ext-module.git

解压
$ tar zxvf pcre-8.40.tar.gz
$ tar zxvf zlib-1.2.11.tar.gz
$ tar zxvf openssl-1.1.0c.tar.gz
$ tar zxvf nginx-1.11.8.tar.gz

2.1) 安装 PCRE
$ cd /home/username/Downloads/pcre-8.40
$ ./configure
$ make && make install

2.2) 安装 Zlib
$ cd /home/username/Downloads/zlib-1.2.11
$ ./configure
$ make && make install

2.3) 安装 OpenSSL
$ cd /home/username/Downloads/openssl-1.1.0c
$ ./config --prefix=/usr
$ make && make install

2.4) 安装 Nginx + nginx-dav-ext-module
$ cd /home/username/Downloads/nginx-1.11.8
$ ./configure --user=nginx --group=nginx --sbin-path=/usr/sbin/nginx --conf-path=/etc/nginx/nginx.conf --error-log-path=/var/log/nginx/error.log --http-log-path=/var/log/nginx/access.log --with-http_ssl_module --with-stream --without-http_empty_gif_module --with-http_dav_module --with-pcre=../pcre-8.40 --with-zlib=../zlib-1.2.11 --add-module=../nginx-dav-ext-module
$ make && make install

3. 设置

3.1) 编辑 nginx.conf

$ gedit /etc/nginx/nginx.conf

user nginx;
worker_processes auto;
error_log /var/log/nginx/error.log;
pid /run/nginx.pid;

events {
    worker_connections 1024;
}

http {
    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for"';

    access_log  /var/log/nginx/access.log  main;

    sendfile            on;
    tcp_nopush          on;
    tcp_nodelay         on;
    keepalive_timeout   65;
    types_hash_max_size 2048;

    include /etc/nginx/conf.d/*.conf;
}

3.2) 创建 webdav.conf

$ mkdir -p /etc/nginx/conf.d
$ gedit /etc/nginx/conf.d/webdav.conf

server {
        listen  80;
        server_name  localhost;

        location /webdav {
root  /var;
autoindex  on;

dav_methods  PUT DELETE MKCOL COPY MOVE;
dav_ext_methods  PROPFIND OPTIONS;

create_full_put_path  on;
client_max_body_size  1G;
client_body_temp_path  /var/temp;

dav_access  user:rw group:r all:r;

auth_basic  "Authorized Users Only";
auth_basic_user_file  /var/.htpasswd;
       }
}

3.3) 创建 nginx.service

$ gedit /usr/lib/systemd/system/nginx.service

[Unit]
Description=The nginx HTTP and reverse proxy server
After=network.target remote-fs.target nss-lookup.target

[Service]
Type=forking
PIDFile=/run/nginx.pid
# Nginx will fail to start if /run/nginx.pid already exists but has the wrong
# SELinux context. This might happen when running `nginx -t` from the cmdline.
# https://bugzilla.redhat.com/show_bug.cgi?id=1268621
ExecStartPre=/usr/bin/rm -f /run/nginx.pid
ExecStartPre=/usr/sbin/nginx -t
ExecStart=/usr/sbin/nginx
ExecReload=/bin/kill -s HUP $MAINPID
KillMode=process
KillSignal=SIGQUIT
TimeoutStopSec=5
PrivateTmp=true

[Install]
WantedBy=multi-user.target

4. 准备 Nginx 启动

$ nginx -t

$ systemctl enable nginx.service

5. 防火壁

Ubuntu
$ systemctl start ufw

$ ufw allow 80/tcp

CentOS / Fedora
$ systemctl start firewalld

$ firewall-cmd --get-active-zones
$ firewall-cmd --permanent --add-service=http --zone=home
$ firewall-cmd --reload
$ firewall-cmd --list-all --zone=home

OpenSUSE
http://jasonmun.blogspot.my/2017/01/opensuse-firewall.html

然后重启

6. 客户端

Fedora
$ dnf install cadaver

CentOS
$ yum install cadaver

OpenSUSE
$ zypper install cadaver

$ cadaver http://127.0.0.1/webdav

BitKinex
http://www.bitkinex.com/download

WinSCP
https://winscp.net/eng/download.php

没有评论:

发表评论