Skip to content

How to install Caddy2 on Ubuntu22.04

Caddy2 is powerful opensource web server. Compared to other web servers, such as Apache2/Nigix, Caddy can deploy https automaticly, and Caddy is very easy to config.

Install Caddy2

install prerequisites libraries

sudo apt update
sudo apt install -y debian-keyring debian-archive-keyring apt-transport-https

add software repositorie

curl -1sLf 'https://dl.cloudsmith.io/public/caddy/stable/gpg.key' | sudo gpg --dearmor -o /usr/share/keyrings/caddy-stable-archive-keyring.gpg
curl -1sLf 'https://dl.cloudsmith.io/public/caddy/stable/debian.deb.txt' | sudo tee /etc/apt/sources.list.d/caddy-stable.list

update repositorie

sudo apt update

installation

sudo apt install caddy

Check Installation

ps -ef | grep caddy

Then, the shell outputs:

caddy 2411 1 0 01:03 ? 00:00:00 /usr/bin/caddy run –environ –config /etc/caddy/Caddyfile

Now, Caddy is running.

Enter your server’s IP in browser, then you will see the welcome page from Caddy.

Config Https(optional)

sudo vi /etc/caddy/Caddyfile

We can see the web directory in caddy’s default configuration file is /usr/share/caddy.

replace :80 with your domain.

point your domain to your server’s IP. wait few minutes for DNS resolution ready. Then restart Caddy server.

sudo caddy stop
sudo caddy start

Enter your domain in browser. Now you can see the website encrypted by https.

2 Comments

Leave a Reply