Install Caddy Web Server on Rocky Linux 9 | Ultimate Server
In this guide on the Orcacore website, we want to teach you How To Install Caddy Web Server on Rocky Linux 9. The Caddy web server is an open-source, HTTP/2-enabled web server written in Go.
The server is designed to be simple, efficient, and portable. Caddy claims to be “The Ultimate Server,” and aims to make web hosting “as easy as it should be.” The open-source, cross-platform web server runs on Linux, macOS, Windows, BSD, and Solaris. It’s also licensed under Apache License 2.0.
Caddy has several features that set it apart. Notably, it supports automatic HTTPS using Let’s Encrypt. This feature means that you can access all websites served by Caddy over a secure HTTPS connection.
Caddy also comes with a web-based administration interface. This tool makes it easy to manage multiple websites on a single server. Caddy is highly extensible, and you can customize it to fit almost any need. Let’s get started with learning how to Install Caddy Web Server on Rocky Linux 9.
Steps To Install and Configure Caddy Web Server on Rocky Linux 9
To complete this guide, you must log in to your server as a non-root user with sudo privileges and set up a basic firewall. To do this, you can follow our guide, the Initial Server Setup with Rocky Linux 9.
Also, you need a domain name that is pointed to your server’s IP address.
1. Install Caddy Web Server on Rocky Linux 9
First, you need to update your local package index with the following command:
sudo dnf update
By default, Caddy is not available in the default Rocky Linux repository. So you need to add the Copr repository to your server.
The Copr (Cool Other Package Repo) is a Fedora project to help make building and managing third-party package repositories easy.
Install Copr Repository
To do this, run the following command:
sudo dnf install 'dnf-command(copr)'
Then, enable the Caddy repository on Rocky Linux 9 with the following command:
sudo dnf copr enable @caddy/caddy
**<mark>Output</mark>**
Repository successfully enabled.
Again you need to run the system update:
sudo dnf update
**<mark>Output</mark>**
Copr repo for caddy owned by @caddy 1.5 kB/s | 1.4 kB 00:00
Dependencies resolved.
Nothing to do.
Complete!
Install Caddy
Now use the following command to install Caddy on Rocky Linux 9:
sudo dnf install caddy -y
Next, start and enable your Caddy service with the commands below:
$ sudo systemctl start caddy
$ sudo systemctl enable caddy
Verify that your Caddy service is active and running on your server with the command below:
sudo systemctl status caddy
In your output you will see:

Now that you have Caddy installed and running on your Rocky Linux 9, let’s see how to create a new site on the Caddy web server.
2. Create a Caddy Site on Rocky Linux 9
This step is similar to the Apache virtual hosts or Nginx server blocks. First, create a directory for your site with the command below:
sudo mkdir -p /var/www/<mark>your-domain</mark>/html
Then, you need to create a directory for the logs:
sudo mkdir /var/log/caddy
Set the correct ownership for both directories with the commands below:
$ sudo chown caddy:caddy /var/www/<mark>your-domain</mark>/html -R
$ sudo chown caddy:caddy /var/log/caddy
Now you need to create an index.html file in your new site directory with your favorite text editor, here we use vi:
sudo vi /var/www/<mark>your-domain</mark>/html/index.html
Add the following content to the file:
<!DOCTYPE html>
<html>
<head>
<title>Hi</title>
</head>
<body>
<h1>Welcome to orcacore</h1>
</body>
</html>
When you are done, save and close the file.
Edit Caddy Configuration File
Here you need to edit the Caddy configuration file. Open Caddy configuration file with your favorite text editor, here we use vi:
sudo vi /etc/caddy/Caddyfile
Remove all the contents to the file and add the following contents to the file:
<mark>your-domain</mark> {
root * /var/www/<mark>your-domain</mark>/html
file_server
encode gzip
log {
output file /var/log/caddy/<mark>your-domain</mark>.log
}
@static {
file
path *.ico *.css *.js *.gif *.jpg *.jpeg *.png *.svg *.woff *.pdf *.webp
}
header @static Cache-Control max-age=5184000
tls admin@<mark>your-domain</mark>
}
When you are done, save and close the Caddy configuration file.
Then, you need to validate your configuration with the command below:
caddy validate --adapter caddyfile --config /etc/caddy/Caddyfile
Note: If the on-screen output results in a formatted warning, you can fix it by running the command below:
caddy fmt --overwrite /etc/caddy/Caddyfile
Next, restart the Caddy service on Rocky Linux 9 to apply the changes:
sudo systemctl restart caddy
3. Configure Firewall for Caddy Web Server
Here we assumed that you have enabled the firewalld. Now you need to allow traffic on HTTP and HTTPS through the firewall with the following commands:
sudo firewall-cmd --permanent --add-service=http
sudo firewall-cmd --permanent --add-service=https
Reload the firewall to apply the new rules:
sudo systemctl reload firewalld
4. Access Caddy Web Server Page
At this point, you can access the Caddy web server by typing your domain name or server’s IP address in your web browser:
http://<mark>server-ip-or-domain</mark>
You will see the Welcome test page.

For more information, you can visit the Caddy Documentation Page.
Conclusion
At this point, you have learned to Install and Configure Caddy Web Server on Rocky Linux 9. Caddy Web Server on Rocky Linux 9 is used to serve websites and applications with automatic HTTPS, easy configuration, and high performance. It simplifies web server management, provides reverse proxy capabilities, and supports modern protocols like HTTP/2 and HTTP/3. Learning how to Install Caddy Web Server on Rocky Linux 9 is valuable for modern web development.
Hope you enjoy it. You may also like these articles:
How To Install Plesk on Rocky Linux 9
Install Apache Cassandra on Rocky Linux 9
How To Install Netdata on Rocky Linux 9
Alternative Installation Methods for Caddy Web Server on Rocky Linux 9
While the Copr repository method outlined above is a straightforward approach to installing Caddy, alternative methods exist that offer different advantages. Here are two such alternatives: using the official Caddy repository and installing Caddy via Docker.
1. Using the Official Caddy Repository
Caddy provides official repositories for various Linux distributions. Using the official repository ensures that you receive the latest stable releases directly from the Caddy developers. While this wasn’t the method initially used, it’s generally the recommended approach for long-term maintenance.
First, add the Caddy repository to your system. You’ll need to install gnupg
if you don’t have it already:
sudo dnf install gnupg
Then, add the Caddy repository:
sudo rpm --import https://dl.cloudsmith.io/public/caddy/stable/gpg.key
sudo tee /etc/yum.repos.d/caddy.repo <<EOF
[caddy_stable]
name=Caddy Stable Repository
baseurl=https://dl.cloudsmith.io/public/caddy/stable/rpm/el/$releasever/$basearch
enabled=1
gpgcheck=1
gpgkey=https://dl.cloudsmith.io/public/caddy/stable/gpg.key
EOF
Now you can install Caddy:
sudo dnf update
sudo dnf install caddy
The remaining steps for starting, enabling, and configuring Caddy remain the same as in the original guide. This method provides a more direct and potentially more reliable source for updates compared to the Copr repository.
2. Installing Caddy via Docker
Docker provides a containerization solution that allows you to run applications in isolated environments. This can be beneficial for managing dependencies and ensuring consistency across different environments. Caddy offers an official Docker image that simplifies the installation and management process.
First, ensure that Docker is installed on your Rocky Linux 9 system. If not, you can install it with the following commands:
sudo dnf install docker -y
sudo systemctl start docker
sudo systemctl enable docker
Next, pull the official Caddy Docker image:
docker pull caddy
To run Caddy in a Docker container, you’ll need to create a Caddyfile
and a directory to serve your website. Let’s create those:
sudo mkdir -p /opt/caddy/data
sudo mkdir -p /opt/caddy/config
sudo mkdir -p /opt/caddy/site
echo "<h1>Hello from Docker!</h1>" | sudo tee /opt/caddy/site/index.html
Now, create a basic Caddyfile
in /opt/caddy/config/Caddyfile
:
sudo tee /opt/caddy/config/Caddyfile <<EOF
:80 {
root * /usr/share/caddy
file_server
}
EOF
Finally, run the Caddy Docker container, mapping the necessary ports and volumes:
docker run -d --name caddy
-p 80:80
-p 443:443
-v /opt/caddy/site:/usr/share/caddy
-v /opt/caddy/config:/config
-v /opt/caddy/data:/data
caddy
This command does the following:
-d
: Runs the container in detached mode (in the background).--name caddy
: Assigns the name "caddy" to the container.-p 80:80
and-p 443:443
: Maps ports 80 and 443 on the host to the corresponding ports in the container.-v /opt/caddy/site:/usr/share/caddy
: Mounts the/opt/caddy/site
directory on the host to/usr/share/caddy
in the container, making your website files accessible.-v /opt/caddy/config:/config
: Mounts the/opt/caddy/config
directory on the host to/config
in the container, allowing you to configure Caddy via theCaddyfile
.-v /opt/caddy/data:/data
: Mounts the/opt/caddy/data
directory on the host to/data
in the container, for storing Caddy’s data (e.g., Let’s Encrypt certificates).caddy
: Specifies the Docker image to use.
You can now access your website by navigating to the server’s IP address in your web browser. Docker provides a convenient way to manage Caddy, especially in environments where containerization is already in use. Furthermore, you are now more informed on how to Install Caddy Web Server on Rocky Linux 9 in several ways.