Install and Configure Caddy on CentOS 7

Updated by Linode Contributed by Konstantin Kuchinin

Contribute on GitHub

View Project | View File | Edit File


This is a Linode Community guide. If you’re an expert on something for which we need a guide, you too can get paid to write for us.


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
    

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
123
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.

See Also

comments powered by Disqus

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