billysoftacademy.com

Unleash the Power of Caddy: A Streamlined Guide for Fedora Users

Introduction

Caddy is a flexible and high-performance web server that is open-source, cross-platform, and enterprise-ready. Written in the Go language, Caddy can be configured to serve websites directly from its file system or proxy requests to other web servers. It can run on various operating systems such as Linux, macOS, Windows, BSD, and Solaris. If you’re looking for an easy-to-use web server, Caddy is the best option. In this post, we’ll guide you through the installation and usage of Caddy web server on Fedora Linux

Prerequisites

The following is a list of items that are needed to install Caddy Web Server successfully:
1) A desktop or laptop with 4GB RAM, a dual core process and atleast 50GB of free disk space
2) An SSH client such as Putty
3) Fedora 39 Workstation or Server edition
4) For cloud deployment a fully qualified domain name and a public static IP address may be needed
5) A stable internet connection.

Overview

The following is a list of steps covered in this tutorial:
1) Installing Caddy.
2) Creating a new website in Caddy
3) Configuring Caddy for a website
4) Accessing a Caddy website.

Installing Caddy

To install the Caddy web server package on Fedora, you can use the following command:

dnf install caddy -y
After installation, you can verify its version using:
caddy version

The output of this command will show the Caddy version, for example:

2.3.0-1.fc34
Next, you need to modify the default Caddy configuration file. Use the following command to open it:
nano /etc/caddy/Caddyfile
Then make the following changes:
:80 {
root * /usr/share/caddy
file_server
}
Finally, save and close the file, and start and enable the Caddy service using the following command:
systemctl enable --now caddy
You can also check the status of the Caddy service using:
systemctl status caddy
The output of this command should show that the service is active and running. Once the installation and setup are complete, you can access the Caddy default page using your server’s IP address and the URL
https//your-server-ip

Creating a new website in Caddy

We’ll be using Caddy to create a new website. To get started, create a document root and log directory for Caddy. Type the following commands in the terminal:

mkdir -p /var/www/example.com/html
mkdir /var/log/caddy
After creating the directories, it’s essential to assign proper permissions to them. Use the following command to set the right permissions:
chown caddy:caddy /var/www/example.com/html -R
chown caddy:caddy /var/log/caddy
With the directories and permissions set, let’s create an Index page for your website. Type the following command in the terminal:
nano /var/www/example.com/html/index.html
This will open a file editor. Now, copy and paste the code below into the file editor:
< title>HELLO WORLD< /title>
Once you’ve added the code, save and close the file by pressing `ctrl+x`, then `y`, and finally `enter`

Configuring Caddy for a website

To serve your website, you’ll need to configure the Caddy configuration file. Open the file at /etc/caddy/Caddyfile using a text editor like nano. Then, remove the default configuration and replace it with the following:
caddy.example.com:80 {
root * /var/www/example.com/html
file_server
encode gzip

log {
output file /var/log/caddy/example.access.log
}

@static {
file
path *.ico *.css *.js *.gif *.jpg *.jpeg *.png *.svg *.woff *.pdf *.webp
}

header @static Cache-Control max-age=5184000
}
Save the file and close it. To validate the Caddy configuration, run the following command:
caddy validate --adapter caddyfile --config /etc/caddy/Caddyfile
Lastly, restart the Caddy service to apply the changes: systemctl restart caddy

Accessing a Caddy Website

Your Caddy web server has been set up to serve your newly created website. To verify that your website is up and running, simply open your web browser and access it using the specific URL http://caddy.example.com.

Conclusion

In this guide, we have covered the installation and configuration of the Caddy web server on Fedora Linux. We also demonstrated how to create a simple website and configure Caddy to serve it. We explored the key features of Caddy, such as its ease of installation, automatic HTTPS support, and flexible configuration options.

Whether you’re a seasoned web developer or a beginner looking for a lightweight and user-friendly web server, Caddy is a powerful and versatile choice. With its extensive plugin ecosystem and modular architecture, it can be customized to meet a wide range of needs.

We encourage you to experiment with Caddy and explore its vast potential. We also recommend referring to the official documentation for more advanced features and configurations. Remember, Caddy is an actively developed project, so new features and improvements are constantly being added.

We hope this guide has been helpful in getting you started with Caddy.

Scroll to Top