I needed a way to share information (both read and write) as easy as possible with friends in a quite restricted environment (firewall). In many cases, WebDAV which uses standard HTTP port 80 for comunication is a good solution for a file server application.
Clarification: Note that even so a web server is used to host the WebDAV protocol, client access is normally not done via a web browser. A special WebDAV client is required. Fortunately Gnome, KDE, Windows 2000+XP and Mac OS X all include WebDAV clients. Once this client is correctly configured, explorer/finder/nautilus/konqueror can be used to browse files comfortably. See the "Testing" section below to learn how to configure a WebDAV client.
I am going to use apache-2.0.54-r5 in this howto for setup of the DAV server.
Some house-cleaning
You can skip this chapter, if apache is already installed on you system.
If your system (like mine) is a bit older, chances are that your harddisk is cluttered with different versions of apache config files which have been moved around quite a bit. If you experience problems like apache segfaulting, configs are not where they are supposed to be etc., go for a fresh installation (after backing up whatever you want to keep). It is a good idea to do a
Code: Select all
emerge -uD worldfirst, then:
Code: Select all
emerge unmerge apache
rm -Rf /var/www
rm -Rf /etc/apache2
rm /etc/conf.d/apache2
rm /etc/init.d/apache2
emerge apache
mkdir -p /var/www/localhost/htdocs
Code: Select all
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>My WebDAV server</title>
</head>
<body>
Hello, world!
</body>
</html>Code: Select all
rc-update add apache2 default
/etc/init.d/apache2 start
Setting up apache2 for WebDAV
Edit /etc/conf.d/apache2 to make sure the dav modules are loaded:
Code: Select all
APACHE2_OPTS="-D DAV -D DAV_FS"Code: Select all
mkdir -p /var/dav/mydavserver
chown -R apache:apache /var/dav
mkdir -p /var/lib/dav
chown -R apache:apache /var/lib/dav
For the first user use:
Code: Select all
htpasswd2 -c /var/dav/.davpasswd mydavuserFor additional users (existing file .davpasswd) use:
Code: Select all
htpasswd2 /var/dav/.davpasswd mydavuserNow the DAV module needs to be configured. Change the following in /etc/apache2/modules.d/45_mod_dav.conf:
Code: Select all
<IfDefine DAV>
<IfModule !mod_dav.c>
LoadModule dav_module modules/mod_dav.so
</IfModule>
</IfDefine>
<IfDefine DAV_FS>
<IfModule !mod_dav_fs.c>
LoadModule dav_fs_module modules/mod_dav_fs.so
</IfModule>
</IfDefine>
<IfModule mod_dav.c>
Alias /mydavserver /var/dav/mydavserver
DavMinTimeout 600
<Location /mydavserver>
Options None
Dav On
<Limit GET PUT POST DELETE PROPFIND PROPPATCH MKCOL COPY MOVE LOCK UNLOCK>
AuthType Basic
AuthName "WebDAV Restricted Repository"
AuthUserFile /var/dav/.davpasswd
Require valid-user
</Limit>
</Location>
</IfModule>
<IfModule mod_dav_fs.c>
# Location of the WebDAV lock database.
DavLockDB /var/lib/dav/lockdb
</IfModule>Testing
Testing a WebDAV repository from Windows
* Do not use internet explorer or any other web browser for this test.
* Double click the "Network" icon and select "Add network place". This starts the "Add network place wizzard". Select "Chose another network location" (we don't want MSN
* This should bring up a login box with an info text we configured in 45_mod_dav.conf, "WebDAV Restricted Repository" in our example. Once you see this text, you verified, that WevDAV is active.
* Now enter the account created with htpasswd2 and you should see your WebDAV directory with Windows explorer. This should work with Windows 2000 and Windows XP (or 2003 Server).
* According to autarkeia, Windows XP sometimes seems to require a portnumer :80 so try: http://www.mydomain.com:80/mydavserver to correctly access web dav repositories.
Testing a WebDAV repository from Mac OS X Tiger
* Do not use any web browser for this test.
* Start Finder, select menu "GO" option "Connect to server".
* enter http://www.mydomain.com/mydavserver or https://www.mydomain.com/mydavserver if you followed the SSL installation.
* This should bring up a box "WebDAV file system authentication" with information about the URL and realm. The realm again should be exactly what was configured in 45_mod_dav.conf, "WebDAV Restricted Repository" in our example. Once you see this text, you verified, that WevDAV is active.
* Now enter the account created with htpasswd2 and you should see your WebDAV directory. I tested with Mac OS X 10.4.1.
Testing a WebDAV repository from Gnome
* Do not use web browser functionality for this test.
* Start nautilus, select menu "File", option "Connect to server". Select Service type "WebDAV (Http)" or "Secure WevDAV (HTTP)" if you used SSL.
* Enter www.mydomain.com/mydavserver. This shows a login box ttp://www.mydomain.com/WebDAV Restricted Repository. Note the text configured in 45_mod_dav.conf.
* Now enter the account created with htpasswd2 and you should see your WebDAV directory.
Adding more security
Additionally, SSL can be used to encrypt the client server communication. I will use a certificate generated for free at cacert.org (inspired by a CACERT howto on gentoo-wiki.org).
Go to www.cacert.org to create a free account. Validate your domain mydomain.com which is required to generate a certificate for a server myserver.mydomain.com.
Then generate a certificate request that can be given to cacert.org:
Code: Select all
cd /etc/apache2/ssl
openssl genrsa -out myserver.mydomain.com.key 1024
openssl req -new -key myserver.mydomain.com.key -out myserver.mydomain.com.csrNow create a server certificate on cacert.org using the created *.csr file and copy the resulting information into a file myserver.mydomain.com.crt.
Now we need to configure apache. First make sure the SSL module is loaded too, edit /etc/conf.d/apache2 and add the -D SSL:
Code: Select all
APACHE2_OPTS="-D SSL -D DAV -D DAV_FS"Code: Select all
SSLCertificateFile conf/ssl/myserver.mydomain.com.crt
SSLCertificateKeyFile conf/ssl/myserver.mydomain.com.keyhttps://myserver.mydomain.com/mydavserver
If you want to allow only SSL access, add (as niltonvolpato pointed out) a SSLRequireSSL into the <Location> section:
Code: Select all
<Location /mydavserver>
SSLRequireSSL
...
</Location>I'll try to list a few reasons for the 403 forbidden error.
* First of all, a normal web browser will not list a web dav directory, instead you get this forbidden error. Make sure you are actually using a webdav client to access your server and not a web browser. See the testing chapter in the FAQ how build-in webdav clients are used for different client operating systems. Additionally a web browser can be used to access a single file, so entering the webdav-url + file-name should work too.
If you get messages like: "client denied by server configuration: /var/dav/svn", try:
* In some configurations of apache config (httpd.conf) inherited permissions deny access. Adding:
Code: Select all
...
AllowOverride None
Order allow,deny
Allow from all
</Location>
* Make sure, your webdav repository has group and owner of the username of apache server (ususally 'apache')
* Double check the account creation via htpasswd2 (cat /var/dav/.davpasswd and verify that all required user account are there.)
* Check the apache configuration in 45_mod_dav.conf
* Check the logs (/var/log/apache)
* Verify that standard web functionality is working (e.g. using the small test html file created above.)
* If connecting from Windows XP fails, try to add a port number :80 into the connection URL: http://www.mydomain.com:80/mydavserver this seems to be a work around for some XP issues.
Credits
This got me started:
http://forums.gentoo.org/viewtopic-t-25 ... howto.html
http://gentoo-wiki.com/HOWTO_cacert.org ... rtificates
Further information
http://httpd.apache.org/docs-2.0/mod/mod_dav.html
History
2005-06-04: v1.01: Some beautification, no essential changes.
2005-06-04: v1.02: clarification on usage of htpasswd2
2005-06-16: v1.03: Expanded testing section and created troubleshooting section
2005-07-03: v1.04: Added tip for connecting from Windows XP using port number :80
2005-08-03: v1.05: Fix for access-denied because of inherited permissions added
2005-08-11: v1.06: Tip for ssl-only access to WebDAV added, SSLRequireSSL



