FedoraRHEL Based

How To Install Caddy Web Server on Fedora 41

Install Caddy Web Server on Fedora 41

In this tutorial, we will show you how to install Caddy Web Server on Fedora 41. Caddy is a modern web server that is known for its simplicity and automatic HTTPS capabilities. It is an excellent choice for developers looking to host web applications or static sites without the complexities often associated with traditional web servers. This guide will walk you through the process of installing Caddy Web Server on Fedora 41, configuring it, and troubleshooting common issues.

Prerequisites

Before you begin the installation process, ensure that your Fedora 41 system meets the following prerequisites:

  • A running instance of Fedora 41.
  • Basic knowledge of Linux command line operations.
  • Root or sudo access to install packages and configure services.

It is also advisable to update your system to ensure all packages are current. You can do this by running:

sudo dnf update -y

Installing Caddy on Fedora 41

Update Your System

Start by updating your system to ensure that you have the latest package information:

sudo dnf update -y

Install Caddy from the Default Repository

Caddy is available in the default repositories for Fedora, making installation straightforward. Use the following command to install Caddy:

sudo dnf install caddy -y

After installation, verify that Caddy has been installed correctly by checking its version:

caddy version

Configure Caddy as a Systemd Service

Caddy can be run as a service using systemd, which allows it to start automatically at boot time. Follow these steps to configure it:

    • Create a directory for the Caddy configuration files:
sudo mkdir /etc/caddy
    • Create a new service file for Caddy:
sudo nano /etc/systemd/system/caddy.service
    • Add the following content to the service file:
[Unit]
Description=Caddy Web Server
After=network.target

[Service]
User=caddy
Group=caddy
ExecStart=/usr/bin/caddy run --config /etc/caddy/Caddyfile --adapter caddyfile
Restart=on-failure

[Install]
WantedBy=multi-user.target
    • Save and exit the editor (CTRL + X, then Y, then ENTER).
    • Reload systemd to recognize the new service file:
sudo systemctl daemon-reload
    • Enable and start the Caddy service:
sudo systemctl enable --now caddy
    • Check the status of the Caddy service to ensure it is running properly:
sudo systemctl status caddy

Configuring Caddy

Understanding the Caddyfile

The Caddyfile is where you define how your server behaves. It uses a simple syntax that makes it easy to configure various aspects of your web server.

Creating Your First Site

The next step is to create a site that Caddy will serve. Follow these instructions:

    • Create a directory for your site’s files:
sudo mkdir -p /var/www/example.com/html
    • Set permissions for this directory:
sudo chown -R caddy:caddy /var/www/example.com/html
    • Create an index.html file as a test page:
echo '<!doctype html><html><head><title>Hello World</title></head><body><h1>Hello, World!</h1></body></html>' | sudo tee /var/www/example.com/html/index.html
    • Edit the Caddyfile to serve your site:
sudo nano /etc/caddy/Caddyfile

Add the following configuration (replace example.com with your domain):

example.com {
        root * /var/www/example.com/html
        file_server
}
    • Validate your configuration to check for errors:
caddy validate --config /etc/caddy/Caddyfile
    • If validation passes, restart Caddy to apply changes:
sudo systemctl restart caddy
  • Your website should now be accessible via your browser at http://example.com.

Testing Your Installation

Accessing Your Website

You can access your newly created site by navigating to http://example.com in your web browser. If everything is set up correctly, you should see “Hello, World!” displayed.

Install Caddy Web Server on Fedora 41

Troubleshooting Common Issues

If you encounter issues accessing your site, consider the following troubleshooting steps:

  • Caddy Service Status: Check if the Caddy service is running properly by executing:
    sudo systemctl status caddy

    Look for any error messages in the output.

  • Curl Test: Use curl to test if Caddy is responding:
    curl http://localhost:80

    You should receive a response with “Hello, World!” if everything is configured correctly.

  • Caddy Logs: Check logs for additional error messages:
    sud journalctl -u caddy --no-pager | tail -n 50 

    This command will show you the last 50 lines of logs related to the Caddy service.

  • Cors Issues:If you’re using a domain name, ensure DNS records are pointing correctly to your server’s IP address.

Advanced Configuration Options

Enabling HTTPS with Automatic Certificates

Caddy automatically provisions HTTPS certificates using Let’s Encrypt when you specify a domain name in your configuration. Ensure that your domain points to your server’s IP address before enabling HTTPS.

Add this line in your existing site block in the Caddyfile:

{ 
   auto_https on 
}

Setting Up Reverse Proxy (Optional)

If you want to use Caddy as a reverse proxy for another application running on your server, you can modify your Caddyfile like this:

example.com {
   reverse_proxy localhost:8080
}

Congratulations! You have successfully installed Caddy. Thanks for using this tutorial for installing the Caddy Web Server on Fedora 41 system. For additional or useful information, we recommend you check the official Caddy website.

VPS Manage Service Offer
If you don’t have time to do all of this stuff, or if this is not your area of expertise, we offer a service to do “VPS Manage Service Offer”, starting from $10 (Paypal payment). Please contact us to get the best deal!

r00t

r00t is an experienced Linux enthusiast and technical writer with a passion for open-source software. With years of hands-on experience in various Linux distributions, r00t has developed a deep understanding of the Linux ecosystem and its powerful tools. He holds certifications in SCE and has contributed to several open-source projects. r00t is dedicated to sharing her knowledge and expertise through well-researched and informative articles, helping others navigate the world of Linux with confidence.
Back to top button