1、配置Nginx以支持WebDav:
Webdav是nginx一个组件,默认编译nginx时是没有安装这个组件的。
如果跟应用公用一个nginx,需要重新编译安装nginx,重新安装前需要备份好原来的nginx.conf。
1.1编译安装
上传nginx源码nginx-1.12.2.tar.gz到/root目录下。
$ tar zxvf nginx-1.12.2.tar.gz //解压nginx源码
$ cd nginx-1.12.2
$ ./configure --prefix=/opt/nginx --with-http_dav_module //编译时增加web_dav模块
$ make && make install
Nginx成功安装在/opt/nginx目录下
1.2 webdav配置
1.2.1 编辑nginx.conf
$ vi /opt/nginx/conf/nginx.conf
在server中添加如下配置信息:
这里拿我本机的ambari 为例
location /ambari{
root /opt/apps/www/html;
index index.html index.htm;
autoindex on;
## webdav config
client_body_temp_path /tmp;
dav_methods PUT DELETE MKCOL COPY MOVE;
create_full_put_path on;
dav_access group:rw all:r;
}
如下图所示:
1.2.2、Nginx的root目录/opt/apps/www/html默认是只读的,需要加写权限:
$ mkdir –P /opt/apps/www/html/ambari;
$ chmod 777 /opt/apps/www/html
1.2.3、重启nginx:
$ cd /opt/nginx/sbin
$ ./nginx -t $ nginx -s reload
1.2.4 测试webdav:
$ cd /root
$ echo "this is t.txt!" > t.txt $ curl -T t.txt 192.168.1.101/ambari/t.txt $ ll /opt/apps/www/html
(可以看到t.txt上传到了这里) $ curl 192.168.1.101/ambari/t.txt //查看文件中内容
完