Install and Configure Caddy on CentOS 7

Updated by Linode Contributed by Konstantin Kuchinin

Contribute on GitHub

Report an Issue | View File | Edit File

Install Caddy on CentOS

Caddy is a fast, open-source and security-focused web server written in Go. Caddy includes modern features such as support for virtual hosts, minification of static files, and HTTP/2. Caddy is also the first web-server that can obtain and renew SSL/TLS certificates automatically using Let’s Encrypt.

Before You Begin

  1. Familiarize yourself with our Getting Started guide and complete the steps for setting your Linode’s hostname and timezone.

  2. This guide will use sudo wherever possible. Complete the sections of our Securing Your Server guide to create a standard user account, harden SSH access and remove unnecessary network services.

  3. You will need to register your site’s domain name and follow our DNS Manager Overview guide to point your domain to your Linode.

  4. Update your system:

    sudo yum update
    

Install Caddy

  1. Enable the EPEL repository:

    sudo yum install epel-release
    
  2. Install Caddy:

    sudo yum install caddy
    
Caution
Caddy has recently changed their license. Please read over the license agreement to ensure that you are not violating the license with your project. To use Caddy without a commercial license, you may need to compile from source.

Add Web Content

  1. Set up a home directory, web root, for your website:

    sudo mkdir -p /var/www/my-website
    
  2. Create a test page:

    echo '<!doctype html><head><title>Caddy Test Page</title></head><body><h1>Hello, World!</h1></body></html>' > /var/www/my-website/index.html
    
  3. Restore the correct selinux labels on the web root:

    sudo restorecon -r /var/www/my-website
    

Configure the Caddyfile

Add your hostname and web root to the Caddy configuration. Replace example.com with your site’s domain name:

/etc/caddy/conf.d/my-website.conf
1
2
3
example.com {
root /var/www/my-website
}

Enable the Caddy Service

  1. Enable the Caddy service:

    sudo systemctl enable --now caddy.service
    
  2. Type your domain into a browser window on your local machine and you should see the test page. If everything is configured correctly, you should see a green lock symbol in the URL bar, indicating that your connection is secure.

More Information

You may wish to consult the following resources for additional information on this topic. While these are provided in the hope that they will be useful, please note that we cannot vouch for the accuracy or timeliness of externally hosted materials.

Join our Community

Find answers, ask questions, and help others.

This guide is published under a CC BY-ND 4.0 license.