Skip to content

Instantly share code, notes, and snippets.

@detroitenglish
Last active October 14, 2019 18:30
Show Gist options
  • Save detroitenglish/d0bcc7e9d57a2f7ec8241da898a796e1 to your computer and use it in GitHub Desktop.
Save detroitenglish/d0bcc7e9d57a2f7ec8241da898a796e1 to your computer and use it in GitHub Desktop.
Caddy Server via Docker for Pi-Hole on Raspberry Pi
# Copy this file to directory /etc/caddy
# i.e. as /etc/caddy/Caddyfile
:80 {
root /srv/pihole
errors stderr
proxy / 127.0.0.1:8012 {
transparent
}
}
{$PIHOLE_DOMAIN} {
root /srv/pihole
errors stderr
basicauth /auth "{$BASICAUTH_USER}" "{$BASICAUTH_PASSWORD}"
rewrite {
if {path} starts_with /admin
if {$BASICAUTH_USER} match "."
if {$BASICAUTH_PASSWORD} match "."
to /auth{uri}
}
rewrite {
ext js
to index.js
}
header / {
-Server
}
proxy / 127.0.0.1:8012 {
transparent
without /auth
}
}
#!/bin/bash
# These are required for auto-managed ssl
LETSENCRYPT_EMAIL=
PIHOLE_DOMAIN=
# Optional additional security layer
BASICAUTH_USER=
BASICAUTH_PASSWORD=
if [ ! -f /etc/caddy/Caddyfile ];
then
echo "No Caddyfile present in /etc/caddy - aborting!";
exit 1;
fi
# Check domain variable
if [ ! -n "$PIHOLE_DOMAIN" ];
then
echo "Pihole domain not provided - running locally at http://127.0.0.1:80";
PIHOLE_DOMAIN="127.0.0.1:80";
else
echo "Using domain '$PIHOLE_DOMAIN'";
fi
if [[ ! "$PIHOLE_DOMAIN" =~ ":80$" ]];
then
# Check for email, and bail without it
if [ -n "$LETSENCRYPT_EMAIL" ];
then
echo "Registering email address '$LETSENCRYPT_EMAIL'";
else
echo "LETSENCRYPT_EMAIL is not provided - running locally at http://127.0.0.1:80";
PIHOLE_DOMAIN="127.0.0.1:80";
fi
fi
mkdir -p /etc/ssl/caddy
chmod 0750 /etc/ssl/caddy
# Changing pihole webserver to port 8012
sed -i 's@= 80$@= 8012@' /etc/lighttpd/lighttpd.conf
echo 'Restarting the pihole webserver on port 8012...'
service lighttpd restart
# pull latest caddy image for arm...
docker pull elswork/arm-caddy:latest
# stop any running container
docker stop caddy || echo "caddy not running"
# remove running container (for updating the image)
docker rm caddy || echo "caddy container not present"
# start the party
docker run -d --name caddy \
--restart unless-stopped \
--network host \
-v /etc/ssl/caddy:/root/.caddy \
-v /var/www/html:/srv \
-v /etc/caddy/Caddyfile:/etc/Caddyfile \
-e BASICAUTH_USER="${BASICAUTH_USER:=""}" \
-e BASICAUTH_PASSWORD="${BASICAUTH_PASSWORD:=""}" \
-e PIHOLE_DOMAIN="$PIHOLE_DOMAIN" \
elswork/arm-caddy:latest \
-conf="/etc/Caddyfile" -agree=true \
-email="${LETSENCRYPT_EMAIL:=""}" -root=/var/tmp -log=stdout
docker ps
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment