Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
bash script to install and set up Caddy web server with a static website hosted on a GitHub repository
# Install script for Ubuntu server 16.0+.
# Installs and sets up Caddy web server with a static website hosted on a GitHub repository.
# Used in
# This script is a condensed version of
# Download and extract Caddy :
wget -O caddy.tar.gz ""
mkdir caddy
tar vxf caddy.tar.gz -C caddy
cd caddy
# install the binary :
sudo cp caddy /usr/local/bin
sudo chown root:root /usr/local/bin/caddy
sudo chmod 755 /usr/local/bin/caddy
# allow it to listen on protected ports :
sudo setcap 'cap_net_bind_service=+ep' /usr/local/bin/caddy
# create the configuration directories and set proper permissions :
sudo mkdir /etc/caddy
sudo chown -R root:www-data /etc/caddy
sudo mkdir /etc/ssl/caddy
sudo chown -R www-data:root /etc/ssl/caddy
sudo chmod 0770 /etc/ssl/caddy
# install the Systemd service file :
sudo cp init/linux-systemd/caddy.service /etc/systemd/system/
sudo chown root:root /etc/systemd/system/caddy.service
sudo chmod 644 /etc/systemd/system/caddy.service
sudo systemctl daemon-reload
# get external IP (cf.
IP=`dig +short`
# Use to have a valid domain name for HTTPS
# write a default Caddyfile
cat <<EOM | sudo tee /etc/caddy/Caddyfile
https://$ {
internal /.git
redir 301 {
if {scheme} is http
/ https://{host}{uri}
git {
interval 300
# start Caddy service
sudo systemctl start caddy
sudo systemctl enable caddy
echo "wait 10 seconds ..."
sleep 10
sudo systemctl restart caddy
echo "last wait of 10 seconds ..."
sleep 10
echo "All done ! open $URL in your browser."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment