Last active
March 3, 2023 16:55
-
-
Save stokito/0a6274106d407ba6d9fb776e7773445d to your computer and use it in GitHub Desktop.
Lighttpd WebDAV+BasicAuth+CORS
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
server.modules += ( "mod_webdav", "mod_setenv" ) | |
$HTTP["url"] =~ "^/dav($|/)" { | |
webdav.activate := "enable" | |
server.document-root := "/srv/disk/" | |
# skip basic auth check for OPTIONS method from CORS preflight request | |
$HTTP["request-method"] != "OPTIONS" { | |
auth.backend := "plain" | |
auth.backend.plain.userfile := "/etc/lighttpd/webdav.shadow" | |
auth.require := ( | |
# alice and bob have their own home directories but admin user can see them too | |
"/dav/alice/"=>("method"=>"basic","realm"=>"disk","require"=>"user=alice|user=admin"), | |
"/dav/bob/"=>("method"=>"basic","realm"=>"disk","require"=>"user=bob|user=admin"), | |
"/dav/"=>("method"=>"basic","realm"=>"disk","require"=>"valid-user") | |
) | |
server.dir-listing := "enable" | |
dir-listing.encoding := "utf-8" | |
} | |
# For CORS we ned to allow all origins | |
setenv.add-response-header += ( | |
"Access-Control-Allow-Origin" => "*", | |
"Access-Control-Allow-Credentials" => "true" | |
) | |
# For CORS OPTIONS requests we should say which methods are allowed | |
$HTTP["request-method"] == "OPTIONS" { | |
setenv.add-response-header += ( | |
"Access-Control-Allow-Methods" => "HEAD, GET, DELETE, PUT, PATCH, MOVE, MKCOL, COPY, LOCK, UNLOCK, PROPFIND, PROPPATCH, ORDERPATCH, OPTIONS", | |
"Access-Control-Expose-Headers" => "Content-Range, Date, Etag, Last-Modified, Authorization, MS-Author-Via, DAV", | |
"Access-Control-Allow-Headers" => "Content-Type, Accept, Accept-Encoding, Accept-Language, Range, Referer, Cache-Control, Authorization, Accept-Range, If-Modified-Since, Connection, TE, Depth, DNT, If-Match, Destination, Overwrite", | |
"Access-Control-Max-Age" => "60", | |
"Timing-Allow-Origin" => "*" | |
) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
https://github.com/stokito/awesome-webdav/blob/main/readme.md#pwa-and-online-apps