nginx+webdav

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 //查看文件中內容

 

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章