Skip to content

Instantly share code, notes, and snippets.

@jmaupetit
Last active March 11, 2022 15:17
Show Gist options
  • Save jmaupetit/20e60f61ef5817bac20ac80b94991145 to your computer and use it in GitHub Desktop.
Save jmaupetit/20e60f61ef5817bac20ac80b94991145 to your computer and use it in GitHub Desktop.
X-Accel-redirect example using Caddy2 server

Start services:

docker-compose up

Test x-accel-redirect for POST requests:

curl -v -d '{"foo": 2}' http://localhost:8000/test
:8001
log
header X-Accel-Redirect "/back"
respond "Proceed!"
:8002
log
respond "I'm back!"
version: "3.5"
services:
front:
image: caddy:2.4.6
restart: unless-stopped
ports:
- "8000:8000"
volumes:
- ./front:/etc/caddy/Caddyfile
depends_on:
- acl
- back
acl:
image: caddy:2.4.6
restart: unless-stopped
ports:
- "8001:8001"
volumes:
- ./acl:/etc/caddy/Caddyfile
back:
image: caddy:2.4.6
restart: unless-stopped
ports:
- "8002:8002"
volumes:
- ./back:/etc/caddy/Caddyfile
:8000
log
reverse_proxy * acl:8001 {
@accel header X-Accel-Redirect *
handle_response @accel {
rewrite {http.reverse_proxy.header.X-Accel-Redirect}
reverse_proxy back:8002
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment