我的視訊列

Loading...

2011年8月23日 星期二

Ubuntu 上設定給Ipad的WebDav


使用IPad經常有需要將檔案儲存在伺服器上這份記錄使用Ubuntu 10.10伺服器及在現有的Apache2上建立WebDav步驟:
  1. 取得權限
    • 因為以下的所有動作都必須有管理者身分,因此第一個步驟就是取得控制權
sudo su
  1. 安裝WebDAV
    1. 如果Apache尚未安裝,請先安裝:
apt-get install apache2
    1. 啟動 WebDAV 模組:
a2enmod dav_fs
a2enmod dav
  • 重新啟動Apache:
/etc/init.d/apache2 restart
3 建立虛擬主機 I will now create a default Apache vhost in the directory /var/www/web1/web. For this purpose, I will modify the default Apache vhost configuration in /etc/apache2/sites-available/default. If you already have a vhost for which you'd like to enable WebDAV, you must adjust this tutorial to your situation.
First, we create the directory /var/www/web1/web and make the Apache user (www-data) the owner of that directory:
1: mkdir -p /var/www/web1/web
 2: chown www-data /var/www/web1/web
Then we back up the default Apache vhost configuration (/etc/apache2/sites-available/default) and create our own one:
1: mv /etc/apache2/sites-available/default /etc/apache2/sites-available/default_orig
 2: vi /etc/apache2/sites-available/default
 1: NameVirtualHost *
 2: <VirtualHost *>
 3:         ServerAdmin webmaster@localhost
 4: 
 5:         DocumentRoot /var/www/web1/web/
 6:         <Directory /var/www/web1/web/>
 7:                 Options Indexes MultiViews
 8:                 AllowOverride None
 9:                 Order allow,deny
10:                 allow from all
11:         </Directory>
12: 
13: </VirtualHost>
Then reload Apache:
1: /etc/init.d/apache2 reload


4 Configure The Virtual Host For WebDAV
Now we create the WebDAV password file /var/www/web1/passwd.dav with the user test (the -c switch creates the file if it does not exist):
1: htpasswd -c /var/www/web1/passwd.dav test
You will be asked to type in a password for the user test.
(Please don't use the -c switch if /var/www/web1/passwd.dav is already existing because this will recreate the file from scratch, meaning you lose all users in that file!)
Now we change the permissions of the /var/www/web1/passwd.dav file so that only root and the members of the www-data group can access it:
1: chown root:www-data /var/www/web1/passwd.dav
 2: chmod 640 /var/www/web1/passwd.dav
Now we modify our vhost in /etc/apache2/sites-available/default and add the following lines to it:
1: vi /etc/apache2/sites-available/default
 1: [...]
 2:         Alias /webdav /var/www/web1/web
 3: 
 4:         <Location /webdav>
 5:            DAV On
 6:            AuthType Basic
 7:            AuthName "webdav"
 8:            AuthUserFile /var/www/web1/passwd.dav
 9:            Require valid-user
10:        </Location>
11: [...]
The Alias directive makes (together with <Location>) that when you call /webdav, WebDAV is invoked, but you can still access the whole document root of the vhost. All other URLs of that vhost are still "normal" HTTP.
The final vhost should look like this:
1: NameVirtualHost *
 2: <VirtualHost *>
 3:         ServerAdmin webmaster@localhost
 4: 
 5:         DocumentRoot /var/www/web1/web/
 6:         <Directory /var/www/web1/web/>
 7:                 Options Indexes MultiViews
 8:                 AllowOverride None
 9:                 Order allow,deny
10:                 allow from all
11:         </Directory>
12: 
13:         Alias /webdav /var/www/web1/web
14: 
15:         <Location /webdav>
16:            DAV On
17:            AuthType Basic
18:            AuthName "webdav"
19:            AuthUserFile /var/www/web1/passwd.dav
20:            Require valid-user
21:        </Location>
22: </VirtualHost>
Reload Apache afterwards:
1: /etc/init.d/apache2 reload


5 Testing WebDAV

We will now install cadaver, a command-line WebDAV client:
1: apt-get install cadaver
To test if WebDAV works, type:
1: cadaver http://localhost/webdav/
You should be prompted for a user name. Type in test and then the password for the user test. If all goes well, you should be granted access which means WebDAV is working ok. Type quit to leave the WebDAV shell:

1: root@server1:~# cadaver http://localhost/webdav/
 2: Authentication required for webdav on server `localhost':
 3: Username: test
 4: Password:
 5: dav:/webdav/> quit
 6: Connection to `localhost' closed.
 7: root@server1:~#

轉貼自:設定給 Ipad 的 WebDav - 治平隨筆