mholt / caddy-webdav

WebDAV handler module for Caddy
Apache License 2.0
228 stars 24 forks source link

webdav can not work in caddy v2 #9

Closed cnkmmk closed 4 years ago

cnkmmk commented 4 years ago

I want use webdav with caddy v2, but can not work.

caddy version: 2.1.1 My website root: /home/website, webdav root: /home/webdav

Caddyfile:

{
  http_port 8080
  order webdav last
}
http:// {
  root * /home/website
  log {
    output stdout
  }
  file_server
  webdav /webdav/* {
    root /home/
  }
}

When file_server is normal, the website can be accessed, but WebDAV cannot work. The comment file_server, WebDAV works normally and the website cannot be accessed.

wader commented 4 years ago

Hello, have a look at #8 #7

cnkmmk commented 4 years ago

Is this?, I don't know golang.

{
  http_port 8080
  order webdav last
}
http:// {
  root * /home/website
  log {
    output stdout
  }
  file_server
  webdav /webdav/* {
    prefix /webdav/
    root /home/
  }
}
wader commented 4 years ago

The webdav config looks correct i think. Still not working?

cnkmmk commented 4 years ago

Yes. website is good, webdav can not work.

wader commented 4 years ago

What kind of error do you get? can you reproduce it with curl? maybe paste output?

You could try something like

curl -v -H "Depth: 1" -X PROPFIND http://host/webdav/
cnkmmk commented 4 years ago
root@webdav:/etc/caddy# curl -v -H "Depth: 1" -X PROPFIND http://localhost:8080/webdav/
* Expire in 0 ms for 6 (transfer 0x563c53f50bb0)
* Expire in 1 ms for 1 (transfer 0x563c53f50bb0)
* Expire in 0 ms for 1 (transfer 0x563c53f50bb0)
* Expire in 2 ms for 1 (transfer 0x563c53f50bb0)
* Expire in 0 ms for 1 (transfer 0x563c53f50bb0)
* Expire in 0 ms for 1 (transfer 0x563c53f50bb0)
* Expire in 2 ms for 1 (transfer 0x563c53f50bb0)
* Expire in 0 ms for 1 (transfer 0x563c53f50bb0)
* Expire in 0 ms for 1 (transfer 0x563c53f50bb0)
* Expire in 2 ms for 1 (transfer 0x563c53f50bb0)
* Expire in 0 ms for 1 (transfer 0x563c53f50bb0)
* Expire in 0 ms for 1 (transfer 0x563c53f50bb0)
* Expire in 2 ms for 1 (transfer 0x563c53f50bb0)
* Expire in 0 ms for 1 (transfer 0x563c53f50bb0)
* Expire in 0 ms for 1 (transfer 0x563c53f50bb0)
* Expire in 2 ms for 1 (transfer 0x563c53f50bb0)
* Expire in 0 ms for 1 (transfer 0x563c53f50bb0)
* Expire in 0 ms for 1 (transfer 0x563c53f50bb0)
* Expire in 0 ms for 1 (transfer 0x563c53f50bb0)
*   Trying 127.0.0.1...
* TCP_NODELAY set
* Expire in 149999 ms for 3 (transfer 0x563c53f50bb0)
* Expire in 200 ms for 4 (transfer 0x563c53f50bb0)
* Connected to localhost (127.0.0.1) port 8080 (#0)
> PROPFIND /webdav/ HTTP/1.1
> Host: localhost:8080
> User-Agent: curl/7.64.0
> Accept: */*
> Depth: 1
> 
< HTTP/1.1 404 Not Found
< Server: Caddy
< Date: Mon, 13 Jul 2020 14:31:56 GMT
< Content-Length: 0
< 
* Connection #0 to host localhost left intact
wader commented 4 years ago

I could be that your root * /home/website directive "shadows" your webdav directive because it both matches the same routes and also will be evaluated first i think. Try something like this:

{
  http_port 8080
  order webdav last
}
http:// {
  route /webdav/* {
    webdav {
      prefix /webdav/
      root /home/
    }
  }
  route /* {
    root /home/website
    file_server
  }
  log {
    output stdout
  }
}

You could probably also use the order directive to specify evaluation order.

mholt commented 4 years ago

(Sorry, been away from work stuff this weekend)

@cnkmmk Yes, the file_server is being executed first because you have order webdav last, so the file server is handling the request before it even gets to webdav.

I wrote about this in-depth here in this wiki article: https://caddy.community/t/composing-in-the-caddyfile/8291?u=matt - I encourage a thorough study of its concepts! It will make everything much easier and crystal clear. @wader's solution, as you will notice after reading the wiki article, might be one possible solution, although I think I would rather use handle instead of route so that both don't get executed. If you use route, you would put them all inside one route. (Also, I would drop the /* matcher, it is unnecessary.)

Fortunately, this is not a bug in webdav, nor in Caddy, so I will close this, but feel free to continue discussion if necessary.