Skip to content

Instantly share code, notes, and snippets.

@dimasahmad
Last active July 22, 2022 05:15
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save dimasahmad/6a07a648c0fe433c3b64686ed741fe77 to your computer and use it in GitHub Desktop.
Save dimasahmad/6a07a648c0fe433c3b64686ed741fe77 to your computer and use it in GitHub Desktop.
Install Caddy 2 on Ubuntu
#!/usr/local/env bash
#
# Create a cloud server with Vultr! Get free credits with this affiliate link: https://www.vultr.com/?ref=8498681-6G
#
# (Unofficial) Caddy 2 Installer Script
#
# Tested on Ubuntu 19.10
#
# Caddy 2 is still in beta. Once it released a stable version, this script will be updated to only use stable version.
#
# Caddy documentation: https://caddyserver.com/docs/install
# Check root permission
if [ "$(whoami)" != "root" ]; then
SUDO=sudo
fi
# Update system
${SUDO} apt update && ${SUDO} apt full-upgrade -y
# Define caddy2 version
VER=$(curl -s https://github.com/caddyserver/caddy/releases | egrep -o '(v[0-9]).*(linux_amd64)' | grep caddy2 | grep beta | head -1)
# Get caddy2 binary
${SUDO} wget "https://github.com/caddyserver/caddy/releases/download/${VER}" -O /usr/bin/caddy
# Change file permission
${SUDO} chmod +x /usr/bin/caddy
# Print caddy version
caddy version
# Create a group named caddy
${SUDO} groupadd --system caddy
# Create a user named caddy, with a writebale home folder
${SUDO} useradd --system \
--gid caddy \
--create-home \
--home-dir /var/lib/caddy \
--shell /usr/sbin/nologin \
--comment "Caddy web server" \
caddy
# Get systemd service
${SUDO} wget https://github.com/caddyserver/dist/raw/master/init/caddy.service -O /etc/systemd/system/caddy.service
sudo mkdir /etc/caddy
sudo chown -R root:caddy /etc/caddy
sudo touch /etc/caddy/Caddyfile
# Reload service
${SUDO} systemctl daemon-reload
# Enable service
${SUDO} systemctl enable caddy
# Start service
${SUDO} systemctl start caddy
# Refer to the Caddy docs for more information:
# https://caddyserver.com/docs/caddyfile
:80
reverse_proxy 10.100.100.1:80
@Innei
Copy link

Innei commented Jan 7, 2022

Why not use api.github.com to get latest version of caddy

@Innei
Copy link

Innei commented Jan 7, 2022

Outdated, please update.

@dimasahmad
Copy link
Author

I don't use caddy anymore. You should find another tutorial.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment