Introduction

WebDAV is great once you’ve tried it. We’ll see how to set it up with Lighttpd. I need it to upload images for my photo album.

Installation

For the installation, it’s straightforward:

1
apt-get install lighttpd-mod-webdav

Configuration

Lighttpd

Let’s enable our newly installed module:

1
2
lighty-enable-mod auth
lighty-enable-mod webdav

Edit the Lighttpd configuration file and uncomment this section:

1
2
3
4
5
server.modules              <nowiki>=</nowiki> (
...
            "mod_webdav",
...
)

We’ll add the folder we want to have WebDAV access to below.

  • If you want to restrict by IP, use this example (/etc/lighttpd/lighttpd.conf):
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
...
$HTTP["host"] =~ "^webdav\.(deimos\.fr)" {
    server.document-root = "/var/www/photos/galleries"
    alias.url = ( "(.*)" => "/var/www/photos/galleries" )
    $HTTP["remoteip"] != "192.168.0.0/24" {
        webdav.activate = "enable"
        webdav.is-readonly = "disable"
        auth.backend = "htpasswd"
        auth.backend.htpasswd.userfile = "/var/www/photos/galleries/.htpasswd"
        auth.require = ( "" => ( "method" => "basic",
            "realm" => "webdav",
            "require" => "valid-user" ) ) 
    }   
}
...
  • If you prefer something simpler, use this example (/etc/lighttpd/lighttpd.conf):
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
$["remoteip"] == "^webdav\.(deimos\.fr)" {
    alias.url += ( "/webdav" => "/var/www/photos/galleries" )
    $HTTP["url"] =~ "^webdav($|/)" {
        dir-listing.activate = "enable"
        webdav.activate = "enable"
        webdav.is-readonly = "disable"
        auth.backend = "htpasswd"
        auth.backend.htpasswd.userfile = "/var/www/photos/galleries/.htpasswd"
        auth.require = ("" => "method" => "basic",
             "realm" => "webdav",
             "require" => "valid-user" ) )
    }
}

Finally, restart Lighttpd.

Of course, if you want to go a bit further with all this, you can also connect it to an LDAP directory, for example.

WebDAV

Now let’s configure the file we’re interested in (here /var/www/photos). First, we’ll create an htpasswd file:

1
htpasswd -c /var/www/photos/galleries/.htpasswd www-data

I deliberately chose www-data here. But it’s preferable to use a specific user. Let’s also set the correct permissions:

1
chown www-data. /var/www/photos/galleries/.htpasswd

Resources

Last updated 19 Aug 2009, 07:08 CEST. history