1. Caddy version (caddy version
):
v2.4.3 h1:Y1FaV2N4WO3rBqxSYA8UZsZTQdN+PwcoOcAiZTM8C0I=
2. How I run Caddy:
using a Makefile make reverseproxy
a. System environment:
Linux G4560 5.4.0-77-lowlatency #86-Ubuntu SMP PREEMPT Thu Jun 17 03:26:36 UTC 2021 x86_64 x86_64 x86_64 GNU/Linux
b. Command:
using make reverseproxy
the Makefile:
apiserver:
air -c air.toml
webclient:
sudo chown -R `whoami` /usr/lib/node_modules/
cd svelte/src/vite-plugin-mpa && npm install && npm run build
cd svelte && npm install && npm run dev
reverseproxy:
caddy fmt -overwrite Caddyfile
caddy run -config Caddyfile
d. My complete Caddyfile or JSON config:
{
debug
auto_https off
log {
output stdout
level DEBUG
}
local_certs
}
127.0.0.1:80 {
file_server /upload/* browse {
root ./svelte/dist
}
reverse_proxy * 127.0.0.1:3000
reverse_proxy /api/* 127.0.0.1:9090
}
localhost:80 {
file_server /upload/* browse {
root ./svelte/dist
}
reverse_proxy * 127.0.0.1:3000
reverse_proxy /api/* 127.0.0.1:9090
}
3. The problem Iβm having:
when visiting localhost it cannot access
upload/anyfile
β file server didnβt work
/api/*
works fine (2nd reverse_proxy line)
/*
didnβt work (1st reverse_proxy line, eg. index.html
or apis/index.html
or index/index.html
, but localhost:3000 works)
the project on ./svelte/
directory is nearly similar to GitHub - kokizzu/svelte-mpa
the directory structure
βββ svelte
β βββ dist
β β βββ apis
β β β βββ index.html
β β βββ assets
β β β βββ apis.f873b16e.js
β β β βββ index.36259e27.css
β β β βββ index.9e9f050f.js
β β β βββ main.6a8d7b97.js
β β β βββ main.842b04ae.css
β β β βββ modulepreload-polyfill.b7f2da20.js
β β β βββ root.d86d93ea.js
β β β βββ svelte.d72399d3.png
β β β βββ vendor.905fb7d8.js
β β βββ favicon.ico
β β βββ index
β β β βββ index.html
β β βββ index.html
β β βββ upload
β β βββ dummy.txt
β βββ src
β β βββ assets
β β β βββ svelte.png
β β βββ components
β β β βββ Counter.svelte
β β βββ global.d.ts
β β βββ pages --> these served normally when using localhost:3000
β β β βββ api.js
β β β βββ apis
β β β β βββ App.svelte
β β β β βββ index.html
β β β β βββ main.ts
β β β βββ App.svelte
β β β βββ index
β β β β βββ App.svelte
β β β β βββ index.html
β β β β βββ main.ts
β β β βββ index.html
β β β βββ main.ts
4. Error messages and/or full log output:
2021/08/21 16:20:22.964 INFO using provided configuration {"config_file": "Caddyfile", "config_adapter": ""}
2021/08/21 16:20:22.966 INFO redirected default logger {"from": "stderr", "to": "stdout"}
2021/08/21 16:20:22.966 INFO admin admin endpoint started {"address": "tcp/localhost:2019", "enforce_origin": false, "origins": ["localhost:2019", "[::1]:2019", "127.0.0.1:2019"]}
2021/08/21 16:20:22.966 INFO tls.cache.maintenance started background certificate maintenance {"cache": "0xc0002e8af0"}
2021/08/21 16:20:22.993 INFO pki.ca.local root certificate is already trusted by system {"path": "storage:pki/authorities/local/root.crt"}
2021/08/21 16:20:22.993 DEBUG http starting server loop {"address": "[::]:80", "http3": false, "tls": false}
2021/08/21 16:20:22.993 INFO tls cleaning storage unit {"description": "FileStorage:/home/kyz/.local/share/caddy"}
2021/08/21 16:20:22.993 INFO autosaved config (load with --resume flag) {"file": "/home/kyz/.config/caddy/autosave.json"}
2021/08/21 16:20:22.994 INFO serving initial configuration
2021/08/21 16:20:22.994 INFO tls finished cleaning storage units
testing 1st reverse_proxy
curl localhost/index.html
404 page not found
log: empty
using firefox and brave browser, both 404 page not found
using chrome, it works the same as localhost:3000
and have a log:
2021/08/21 16:26:38.227 DEBUG http.handlers.reverse_proxy upstream roundtrip {"upstream": "127.0.0.1:3000", "request": {"remote_addr": "[::1]:49606", "proto": "HTTP/1.1", "method": "GET", "host": "localhost", "uri": "/favicon.ico", "headers": {"X-Forwarded-For": ["::1"], "User-Agent": ["Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/92.0.4515.159 Safari/537.36"], "Referer": ["http://localhost/"], "Accept": ["image/avif,image/webp,image/apng,image/svg+xml,image/*,*/*;q=0.8"], "Accept-Encoding": ["gzip, deflate, br"], "Accept-Language": ["en-US,en;q=0.9,id;q=0.8"], "X-Forwarded-Proto": ["http"], "Sec-Ch-Ua-Mobile": ["?0"], "Sec-Fetch-Dest": ["image"], "Sec-Fetch-Site": ["same-origin"], "Sec-Fetch-Mode": ["no-cors"], "Pragma": ["no-cache"], "Cache-Control": ["no-cache"], "Sec-Ch-Ua": ["\"Chromium\";v=\"92\", \" Not A;Brand\";v=\"99\", \"Google Chrome\";v=\"92\""]}}, "headers": {"Access-Control-Allow-Origin": ["*"], "Content-Length": ["1150"], "Content-Type": [""], "Last-Modified": ["Thu, 17 Jun 2021 04:09:06 GMT"], "Date": ["Sat, 21 Aug 2021 16:26:38 GMT"], "Keep-Alive": ["timeout=5"], "Etag": ["W/\"1150-1623902946000\""], "Cache-Control": ["no-cache"], "Connection": ["keep-alive"]}, "status": 200}
but sometimes (after killing it didnβt (have same result with firefox or brave browser), sometimes brave and chrome works (with log), but firefox still 404 without any new log on caddy
testing 1st reverse proxy with ip
curl http://127.0.0.1:80/index.html
404 page not found
all 3 browser didnβt work, my /etc/hosts
file:
cat /etc/hosts | grep localhost
127.0.0.1 localhost
::1 ip6-localhost ip6-loopback
testing static file
curl http://localhost/upload/dummy.txt
404 page not found
log: empty
not testing 2nd reverse_proxy since itβs proven but only with chrome and brave, not with firefox
5. What I already tried:
modifying /upload/*
with *
, with lots of combination (actually the first one is all *
going to same multiple endpoints, but now i change it to /api/*
, /upload/*
and *
),
changing port :80
, without port, :7070
, have no effect
already spend more than 6 hours debugging this, I donβt have such problem back then when using caddy v1
UPDATE
tried this one still the same:
{
debug
auto_https off
log {
output stdout
level DEBUG
}
local_certs
}
127.0.0.1:80, localhost:80 {
root ./svelte/dist/upload
@notStatic {
path /upload/*
}
file_server @notStatic
reverse_proxy /api/* 127.0.0.1:9090
reverse_proxy * 127.0.0.1:3000
}
# https://richj.co/caddy-v2-custom-404-error-pages/