1. Caddy version (caddy version
):
v2.4.5
2. How I run Caddy:
Just the official docker container on a Ubuntu server. It’s paired with another docker container that hosts my backend with Django. The details are visible in my docker-compose file below.
a. System environment:
Official docker container caddy:latest
Docker version 20.10.7, build 20.10.7-0ubuntu1~20.04.2
b. Command:
docker-compose up -d
c. Service/unit/compose file:
version: "3.3"
services:
redis:
image: redis:6.0.9
django:
image: 743943630914.dkr.ecr.eu-central-1.amazonaws.com/esmerise-django:latest
deploy:
restart_policy:
condition: on-failure
build:
context: ..
dockerfile: ./docker/Dockerfile.django
volumes:
- ../esmerise:/app/esmerise
caddy:
image: 743943630914.dkr.ecr.eu-central-1.amazonaws.com/esmerise-caddy-dev:latest
command: ["caddy", "run", "--config", "/etc/caddy/Caddyfile"]
restart: on-failure
build:
context: ..
dockerfile: ./docker/Dockerfile.dev.caddy
links: ["django"]
ports:
- 80:80
- 443:443
volumes:
- ../web-build:/www/data
d. My complete Caddyfile or JSON config:
{
debug
on_demand_tls {
ask http://django:8001/api/v1/academies/tls
interval 2m
burst 5
}
}
https:// {
root * /www/data
tls {
on_demand
}
route {
@api path /api/*
reverse_proxy @api http://django:8001
}
route {
@ws {
path /ws/*
header Connection *Upgrade*
header Upgrade websocket
}
reverse_proxy @ws http://django:8001
}
route {
try_files {path} /index.html
file_server /*
}
}
3. The problem I’m having:
Hi! I’m having some problems with Caddy. The server works well in every situation but one: when I try to test an upload that takes more than a few seconds, I get a 502 error. The error arises in a range from 30s to 1m after the upload starting time. Uploads that take less work fine.
It seems to be more timing related than dimension, because if I play with connection throttling uploading little files, I get the same error. On the docker logs I always find two Caddy entries, that I reported below. Nothing from Django.
The patch request for the upload goes to django through the: reverse_proxy @api http://django:8001 that you can see in the Caddyfile above.
4. Error messages and/or full log output:
caddy_1 |{"level":"debug","ts":1633601769.9896336,"logger":"http.handlers.reverse_proxy","msg":"upstream roundtrip","upstream":"django:8001","request":{"remote_addr":"83.49.93.252:62435","proto":"HTTP/2.0","method":"PATCH","host":"dev.esmerise.com","uri":"/api/v1/academies/2/chapters/1/content/32","headers":{"Referer":["https://dev.esmerise.com/cooking/chapter/1/content/32/edit?category=video"],"Sec-Ch-Ua":["\"Google Chrome\";v=\"93\", \" Not;A Brand\";v=\"99\", \"Chromium\";v=\"93\""],"Sec-Ch-Ua-Mobile":["?0"],"Content-Type":["multipart/form-data; boundary=----WebKitFormBoundaryMBNVKtH02Ezx95AA"],"User-Agent":["Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/93.0.4577.63 Safari/537.36"],"Origin":["https://dev.esmerise.com"],"Accept-Language":["en-GB,en;q=0.9,es-ES;q=0.8,es;q=0.7,en-AU;q=0.6,it-IT;q=0.5,it;q=0.4,en-US;q=0.3"],"Cookie":["_fbp=fb.1.2631369334978.1223390255; __stripe_mid=88d74cc4-f42d-46ea-9dc3-1908ac218a6cf345c4; __stripe_mid=88d74cc4-f42d-46ea-9dc3-1908ac218a6cf345c4; _fbc=fb.1.2632566224470.IwAR3G3f3qCrMHzQp3bxuLS57zJfMJ94gmBu2CmvoxrX5H3hBjj3SrYbSLzcE; __stripe_sid=88f0e473-5139-43dc-b860-a6488551c7b96c8654"],"X-Forwarded-For":["83.49.93.252"],"Dnt":["1"],"Authorization":["Token 8a41e1c69568972c602ed85cf062f6f3b7859db1"],"Accept":["application/json"],"Sec-Ch-Ua-Platform":["\"macOS\""],"Sec-Fetch-Site":["same-origin"],"Content-Length":["1564096991"],"Sec-Fetch-Mode":["cors"],"Sec-Fetch-Dest":["empty"],"Accept-Encoding":["gzip, deflate, br"],"X-Forwarded-Proto":["https"]},"tls":{"resumed":false,"version":772,"cipher_suite":4865,"proto":"h2","proto_mutual":true,"server_name":"dev.esmerise.com"}},"duration":60.159858076,"error":"readfrom tcp 172.18.0.5:57596->172.18.0.2:8001: write tcp 172.18.0.5:57596->172.18.0.2:8001: use of closed network connection"}
caddy_1 | {"level":"error","ts":1633601769.9899337,"logger":"http.log.error","msg":"readfrom tcp 172.18.0.5:57596->172.18.0.2:8001: write tcp 172.18.0.5:57596->172.18.0.2:8001: use of closed network connection","request":{"remote_addr":"83.49.93.252:62435","proto":"HTTP/2.0","method":"PATCH","host":"dev.esmerise.com","uri":"/api/v1/academies/2/chapters/1/content/32","headers":{"Sec-Fetch-Mode":["cors"],"Sec-Fetch-Dest":["empty"],"Accept-Encoding":["gzip, deflate, br"],"Content-Length":["1564096991"],"Sec-Ch-Ua-Mobile":["?0"],"Content-Type":["multipart/form-data; boundary=----WebKitFormBoundaryMBNVKtH02Ezx95AA"],"User-Agent":["Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/93.0.4577.63 Safari/537.36"],"Origin":["https://dev.esmerise.com"],"Referer":["https://dev.esmerise.com/cooking/chapter/1/content/32/edit?category=video"],"Sec-Ch-Ua":["\"Google Chrome\";v=\"93\", \" Not;A Brand\";v=\"99\", \"Chromium\";v=\"93\""],"Authorization":["Token 8a41e1c69568972c602ed85cf062f6f3b7859db1"],"Accept":["application/json"],"Sec-Ch-Ua-Platform":["\"macOS\""],"Sec-Fetch-Site":["same-origin"],"Accept-Language":["en-GB,en;q=0.9,es-ES;q=0.8,es;q=0.7,en-AU;q=0.6,it-IT;q=0.5,it;q=0.4,en-US;q=0.3"],"Cookie":["_fbp=fb.1.2631369334978.1223390255; __stripe_mid=88d74cc4-f42d-46ea-9dc3-1908ac218a6cf345c4; __stripe_mid=88d74cc4-f42d-46ea-9dc3-1908ac218a6cf345c4; _fbc=fb.1.2632566224470.IwAR3G3f3qCrMHzQp3bxuLS57zJfMJ94gmBu2CmvoxrX5H3hBjj3SrYbSLzcE; __stripe_sid=88f0e473-5139-43dc-b860-a6488551c7b96c8654"],"Dnt":["1"]},"tls":{"resumed":false,"version":772,"cipher_suite":4865,"proto":"h2","proto_mutual":true,"server_name":"dev.esmerise.com"}},"duration":60.160255159,"status":502,"err_id":"zj9a9r1j0","err_trace":"reverseproxy.statusError (reverseproxy.go:858)"}
5. What I already tried:
I tried setting all the timeouts values to none, checking the server resources to see if I had memory issues, to no awail.