1. Caddy version (caddy version
):
2.4.3
2. How I run Caddy:
I have this Dockerfile I through together. I’m new at Docker, so also curious if there is any improvements to be had here but not relevant to my post:
FROM alpine:3.12.2
ARG VERSION="0.10.11"
RUN apk update && apk upgrade \
&& apk add --no-cache openssh-client git \
&& apk add --no-cache --virtual .build-dependencies tar curl
RUN curl --silent --show-error --fail --location \
--header "Accept: application/tar+gzip, application/x-gzip, application/octet-stream" -o - \
"https://github.com/caddyserver/caddy/releases/download/v2.4.3/caddy_2.4.3_linux_arm64.tar.gz" \
| tar --no-same-owner -C /usr/bin -xz \
&& chmod 0755 /usr/bin/caddy \
&& /usr/bin/caddy version \
&& apk del .build-dependencies
EXPOSE 80 443 2019
# No idea what this does but saw some people with it
VOLUME /root/.caddy
COPY caddy.json /etc/caddy.json
# Put all HTML / CSS / IMAGES in this dir
WORKDIR /dist
COPY . /dist/
ENTRYPOINT ["/usr/bin/caddy"]
CMD ["run", "-config", "/etc/caddy.json", "-resume"]
# to build: docker build -t caddy-project .
# to run: docker run -d --name caddy -p 80:80 -p 443:443 -p 2019:2019 caddy-project run
a. System environment:
Docker, possibly a Kubernetes cluster later.
Docker 20.10.2
b. Command:
docker build -t caddy-project .
docker run -d --name caddy -p 80:80 -p 443:443 -p 2019:2019 caddy-project run
3. The problem I’m having:
I want to know if Caddy can be used as a router between pages and if that is even a good use-case for Caddy. For example, let’s say my website has multiple pages:
www.example.com
www.example.com/blog/
www.example.com/blog/article-july-20
www.example.com/about
www.example.com/contact
Can I use Caddy to basically do this routing? If so, what would be the proper way to do this?
If not, I could take a different approach using Vue Router and trying to make an SPA as well, so I’d also be looking for suggestions on getting that started.
4. Error messages and/or full log output:
None
5. What I already tried:
I haven’t actually thrown together a protetype yet. Sorry! I just want to first gage if using Caddy this way is even possible.
I’m still pretty new as well but I’ll try to write what I think would be a good Caddyfile for such a thing:
www.example.com {
redir https://example.com{uri}
}
example.com {
root * /path/to/index.html
tls /path/to/server.cert /path/to/server.key # map a host to container volume if you want to use certificates stored on the host
reverse_proxy /api/v1/* localhost:5000
file_server
}
example.com/about {
root * /path/to/about.html
tls /path/to/server.cert /path/to/server.key # map a host to container volume if you want to use certificates stored on the host
reverse_proxy /api/v1/* localhost:5000
file_server
}
<repeat this pattern for every page?>
Thanks for your help!