How to Install Caddy Server on Ubuntu 20.04

The Caddy Web Server is an extensible, cross-platform, open-source web server written in Go. Caddy is both a flexible, efficient static file server and a powerful, scalable reverse proxy. Use it to serve your static site with compression, template evaluation, Markdown rendering, and more.

Update the system.

sudo apt update 

sudo apt upgrade 

Add Repository for Caddy Web Server

Add repository for the Stable Release of Caddy using below commands,

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

curl -1sLf 'https://dl.cloudsmith.io/public/caddy/stable/gpg.key' | sudo apt-key add -

curl -1sLf 'https://dl.cloudsmith.io/public/caddy/stable/gpg.key' | sudo apt-key add -

Update repositories using below command,

sudo apt update 

Install Caddy Web Server

sudo apt install caddy

Install Caddy via Snap.

sudo snap install caddy --edge

Configure Caddy Server

Create directory for your website,

Replace caddy.domainhere.info with actual domain.

mkdir -p /var/www/html/caddy.domainhere.info

Open caddy /etc/caddy/Caddyfile configuration file and add your domain name and change website's directory,

vi /etc/caddy/Caddyfile

Replace 80 with your actual domain name and change the root directory

# The Caddyfile is an easy way to configure your Caddy web server.
#
# Unless the file starts with a global options block, the first
# uncommented line is always the address of your site.
#
# To use your own domain name (with automatic HTTPS), first make
# sure your domain's A/AAAA DNS records are properly pointed to
# this machine's public IP, then replace ":80" below with your
# domain name.
:80 {
        # Set this path to your site's directory.
        root * /usr/share/

        # Enable the static file server.
        file_server

        # Another common task is to set up a reverse proxy:
        # reverse_proxy localhost:8080

        # Or serve a PHP site through php-fpm:
        # php_fastcgi localhost:9000
}

# Refer to the Caddy docs for more information:
# https://caddyserver.com/docs/caddyfile

Restart the Caddy Server using below command,

sudo systemctl reload caddy

Configure Firewall

If you are using UFW, you need to allow access to HTTP and HTTPS ports for the server to work.

sudo ufw allow http
sudo ufw allow https

Reload UFW using below command,

ufw reload

Access Caddy Web Server

Now Navigate your browser and enter your IP address or Domain name.

Replace caddy.domainhere.info with your actual domain name

http://caddy.domainhere.info

image


CrownCloud - Get a SSD powered KVM VPS at $4.5/month!
Use the code WELCOME for 10% off!

1 GB RAM / 25 GB SSD / 1 CPU Core / 1 TB Bandwidth per month

Available Locations: LAX | MIA | ATL | FRA | AMS