1. Caddy version (caddy version
):
2.4.6
2. How I run Caddy:
Docker
a. System environment:
Docker Compose with a .env file, which provides {$MY_DOMAIN}
b. Command:
docker-compose up -d
c. Service/unit/compose file:
caddy:
image: caddy
container_name: caddy
restart: unless-stopped
ports:
- "80:80"
- "443:443"
environment:
- MY_DOMAIN
volumes:
- ./Caddyfile:/etc/caddy/Caddyfile:ro
- caddy_data:/data
- caddy_config:/config
- caddy_logs:/var/log/caddy
networks:
- "commstack"
d. My complete Caddyfile or JSON config:
bookwyrm.{$MY_DOMAIN} {
import logging
import hsts
handle / {
reverse_proxy bookwyrm_web_1:8000
}
handle /images/* {
reverse_proxy bookwyrm_nginx_1:8001
}
handle /static/* {
reverse_proxy bookwyrm_nginx_1:8001
}
}
3. The problem I’m having:
Really i’m just looking for help converting this nginx block into Caddy:
server {
listen [::]:443 ssl http2;
listen 443 ssl http2;
server_name your.domain;
add_header Strict-Transport-Security "max-age=31536000; includeSubDomains" always;
location / {
proxy_pass http://localhost:8000;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $host;
}
location /images/ {
proxy_pass http://localhost:8001;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $host;
}
location /static/ {
proxy_pass http://localhost:8001;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $host;
}
}
Trying to run a docker-compose stack which has two web servers - nginx and gunicorn. Everything proxies through the domain name and the root is served by the nginx container, but certain paths ($DOMAIN/images/* and $DOMAIN/static/*) go through the gunicorn container.
I can get content served through the main, nginx, container, but can’t get the /images/ and /static/ to serve, through the gunicorn server.
The Caddy container and the bookwyrm stack are in two different compose files, but in the same network.
4. Error messages and/or full log output:
No error messages
5. What I already tried:
Multiple variations of the above caddyfile, i.e. breaking the two docker containers into their own caddy sections, path vs. path_handle, &c.
6. Links to relevant resources:
the Reverse Proxy section of the docker stack i’m trying to serve - Using a Reverse-Proxy - BookWyrm Documentation