commit a1af12e076dfad03c55fb7edeb401bc6fce5c471 Author: Markus Birth Date: Thu May 26 17:08:41 2016 +0200 Initial commit. diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..c6dc5fb --- /dev/null +++ b/Dockerfile @@ -0,0 +1,31 @@ +#FROM container4armhf/armhf-alpine +FROM alpine + +MAINTAINER Markus Birth + +LABEL description="Caddy HTTP/2 web server" \ + version="1.0" + +ENV AGREE_TOS="true" \ + CADDY_ARCH="amd64" \ + DEFAULT_EMAIL="changeme@example.com" + +COPY ["caddy.d", "/data/caddy.d/"] +COPY ["compile_and_run.sh", "/usr/local/bin/"] + +RUN apk add --update sed wget \ + && mkdir -p /data/caddy.d \ + && wget --no-check-certificate -q -O /tmp/caddy.tar.gz "https://caddyserver.com/download/build?os=linux&arch=${CADDY_ARCH}&features=" \ + && mkdir -p /opt/caddy \ + && cd /opt/caddy \ + && tar xzf /tmp/caddy.tar.gz \ + && rm /tmp/caddy.tar.gz \ + && chmod a+x /usr/local/bin/compile_and_run.sh \ + && apk del wget \ + && rm -rf /var/cache/* + +VOLUME ["/data"] + +EXPOSE 80 443 + +CMD ["/usr/local/bin/compile_and_run.sh"] diff --git a/README.md b/README.md new file mode 100644 index 0000000..21d94be --- /dev/null +++ b/README.md @@ -0,0 +1,54 @@ +Caddyserver Proxy +================= + +This is a Docker image with a bare-bones [Caddyserver](https://caddyserver.com/). + +It is meant to function as an SSL proxy to your intranet web services. + + +Caddyfiles +---------- + +Usually, Caddyserver only supports one single `Caddyfile` for configuration. This +Docker image contains a script which gathers all `*.caddy` files from the +`/data/caddy.d/` directory and concatenates them into one `Caddyfile` before +launching the server. + +This way you can keep your configuration clean. + + +Example +------- + +Here is a simple example to proxy my Subsonic via SSL: + +``` +subsonic.myhost.com { + proxy / http://homeserver:4040/ { + proxy_header Host subsonic.myhost.com + proxy_header Scheme https + # Enable if needed, e.g. for Wetty: + #websocket + } +} +``` + +This will accept HTTPS connections to subsonic.myhost.com on port 443 and +forward them to http://homeserver:4040/. + +Make sure that each of your configured services has a unique hostname so +that Caddyserver can distinguish them. + + +Environment Variables +--------------------- + +* `CADDY_ARCH` --- CPU architecture to use for Caddy, e.g. `386` or `arm`. Default: `amd64` +* `DEFAULT_EMAIL` --- The default email address to use for SSL certificate generation. + Can be overridden in Caddyfiles with the `tls` directive. + + +Volumes +------- + +* `/data` --- holds the Caddyfiles and Logfile. diff --git a/caddy.d/000-default.caddy b/caddy.d/000-default.caddy new file mode 100644 index 0000000..fa99680 --- /dev/null +++ b/caddy.d/000-default.caddy @@ -0,0 +1,3 @@ +:80 { + proxy / http://localhost:81/ +} diff --git a/compile_and_run.sh b/compile_and_run.sh new file mode 100644 index 0000000..1426233 --- /dev/null +++ b/compile_and_run.sh @@ -0,0 +1,6 @@ +#!/bin/sh +BASEPATH="/data" +# http://stackoverflow.com/questions/8183191/concatenating-files-and-insert-new-line-in-between-files +sed -e '$s/$/\n/' -s $BASEPATH/caddy.d/*.caddy > $BASEPATH/Caddyfile + +exec /opt/caddy/caddy -agree=${AGREE_TOS} -email="${DEFAULT_EMAIL}" -conf="${BASEPATH}/Caddyfile" -log="${BASEPATH}/caddy.log"