Install and Configure Caddy on CentOS 7
Updated by Linode Contributed by Konstantin Kuchinin
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
Familiarize yourself with our Getting Started guide and complete the steps for setting your Linode’s hostname and timezone.
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.You will need to register your site’s domain name and follow our DNS Manager Overview guide to point your domain to your Linode.
Update your system:
sudo yum update
Install Caddy
Enable the EPEL repository:
sudo yum install epel-release
Install Caddy:
sudo yum install caddy
CautionCaddy 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
Set up a home directory, web root, for your website:
sudo mkdir -p /var/www/my-website
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
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
Enable the Caddy service:
sudo systemctl enable --now caddy.service
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.