1. Output of caddy version
:
v2.5.2 h1:eCJdLyEyAGzuQTa5Mh3gETnYWDClo1LjtQm2q9RNZrs=
2. How I run Caddy:
Caddy is in front of a Phoenix app run in a container. I want to serve a part of the static files: if all the static files are located at “priv/static”, I want to serve the subfolder “priv/static/react”.
When I run Phoenix in a container under compose (+ db) and Caddy outside of the network with caddy run Caddyfile
, it works: the app renders.
If I integrate in the docker-compose, ie run Caddy in a container in the same network, it fails: “page not working” ,502 from server.
Phoenix runs at port 4000 and I put Caddy at 80.
a. System environment:
MacOS 12.4, Docker 20.10.17, 1.29
b. Command:
caddy run Caddyfile
docker-compose up
c. Service/unit/compose file:
caddy:
image: caddy:2.5.2
restart: unless-stopped
ports:
- "80:80"
# - "443:443"
# - "443:443/udp"
volumes:
- $PWD/Caddyfile:/etc/caddy/Caddyfile:ro
- $PWD/priv/static/react/:/srv
- caddy_data:/data
- caddy_config:/config
d. My complete Caddy config:
http://localhost:80 {
reverse_proxy http://localhost:4000
encode gzip
file_server /react/*
log {
output stdout
format console
}
}
3. The problem I’m having:
4. Error messages and/or full log output:
caddy_1 | {"level":"info","ts":1662508513.5174167,"msg":"using provided configuration","config_file":"/etc/caddy/Caddyfile","config_adapter":"caddyfile"}
phx_1 | 23:55:14.608 [info] Access PhoenixReactWeb.Endpoint at http://localhost:4000
caddy_1 | {"level":"debug","ts":1662508539.5636141,"logger":"http.handlers.reverse_proxy","msg":"selected upstream","dial":"localhost:4000","total_upstreams":1}
caddy_1 | {"level":"debug","ts":1662508539.5705636,"logger":"http.handlers.reverse_proxy","msg":"upstream roundtrip","upstream":"localhost:4000","duration":0.006736875,"request":{"remote_ip":"172.22.0.1","remote_port":"56894","proto":"HTTP/1.1","method":"GET","host":"localhost","uri":"/","headers":{"Sec-Ch-Ua-Platform":["\"macOS\""],"User-Agent":["Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/105.0.0.0 Safari/537.36"],"Sec-Fetch-Dest":["document"],"X-Forwarded-Proto":["http"],"Dnt":["1"],"Sec-Ch-Ua":["\"Google Chrome\";v=\"105\", \"Not)A;Brand\";v=\"8\", \"Chromium\";v=\"105\""],"Sec-Fetch-Site":["none"],"Accept-Encoding":["gzip, deflate, br"],"Upgrade-Insecure-Requests":["1"],"X-Forwarded-Host":["localhost"],"Accept-Language":["en"],"Accept":["text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9"],"Sec-Fetch-User":["?1"],"Sec-Fetch-Mode":["navigate"],"X-Forwarded-For":["172.22.0.1"],"Sec-Ch-Ua-Mobile":["?0"]}},"error":"dial tcp 127.0.0.1:4000: connect: connection refused"}
5. What I already tried:
I imagine a network discovery problem, Phoenix configuration. I used things like “http://caddy” or “http://phoenix” instead of localhost without success.
=> I posted here because I wanted to check that at least my Caddyfile and my Dockerfile are ok, Caddy wise; good for doing what I want, serving and caching some static files in front of Phoenix.
6. Links to relevant resources:
https://hub.docker.com/_/caddy
https://caddyserver.com/docs/quick-starts/static-files
https://caddyserver.com/docs/quick-starts/reverse-proxy