fix: crash when env var WEBDAV_BACKEND is not set

This commit is contained in:
Kingsley Yung 2024-11-16 20:08:25 +08:00 committed by Johannes Millan
parent 32aa4fb628
commit 7d5ccbd7ef
2 changed files with 11 additions and 7 deletions

View file

@ -10,8 +10,6 @@ services:
# (used with the WEBDAV_BACKEND environment variable)
webdav:
image: hacdias/webdav:latest
ports:
- 81:80
volumes:
- ./webdav.yaml:/config.yml:ro
- ./data:/data

View file

@ -1,3 +1,8 @@
# Load environment variables
map "" $webdav_backend {
default "$WEBDAV_BACKEND";
}
server {
listen 80;
server_name localhost;
@ -14,12 +19,13 @@ server {
return 302 /webdav/;
}
location /webdav/ {
set $upstream $WEBDAV_BACKEND;
# note: put the upstream host in a variable first so that nginx can
# starts successfully even if the upstream hsot is not found.
if ($webdav_backend = "") {
return 404;
}
proxy_pass $upstream/;
# note: the trailing slash here matters!
resolver 127.0.0.11; # resolve webdav_backend by docker internal DNS
rewrite ^/webdav/(.*)$ /$1 break; # remove the `/webdav/` prefix
proxy_pass $webdav_backend;
}
# redirect server error pages to the static page /50x.html