Drivetech / django-caddy

Docker Image for reverse proxy django apps with caddyserver and alpine linux
MIT License
13 stars 1 forks source link

How do we add Caddy Plugins? #28

Open codecraf8 opened 4 years ago

codecraf8 commented 4 years ago

I wanted to add gzip, cache, and others.

lgaticaq commented 4 years ago

Hi. the simple way is overwrite the Caddyfile. Ex:

Create a custom Caddyfile

# custom.Caddyfile
0.0.0.0:80
{
  proxy / django:{$PORT} {
    transparent
    except /media /static
  }

  root /var/www

  log /var/log/access.log {
    rotate_size 100 # Rotate after 100 MB
    rotate_age  14  # Keep log files for 14 days
    rotate_keep 10  # Keep at most 10 log files
    rotate_compress # Compress rotated log files in gzip format
  }

  # Custom plugins
  gzip
}

Then run container with custom Caddyfile (-v)

docker run -d --name caddy --link django:django -v static:/var/www/static -v media:/var/www/media -v logs:/var/log -v /path/to/custom.Caddyfile:/etc/Caddyfile -e PORT=8000 lgatica/django-caddy

Or build a custom docker image with custom Caddyfile

FROM lgatica/django-caddy

COPY custom.Caddyfile /etc/Caddyfile
docker build -t my-custom-image .
docker run -d --name caddy --link django:django -v static:/var/www/static -v media:/var/www/media -v logs:/var/log -v /path/to/custom.Caddyfile:/etc/Caddyfile -e PORT=8000 my-custom-image
codecraf8 commented 4 years ago

only gzip works, if you put "cache" as a plugin, it throws error.

lgaticaq commented 4 years ago

Is not possible because this Dockerfile get binary from release and not build, sorry. I recommend use https://hub.docker.com/r/abiosoft/caddy and add a custom Caddyfile