How to Set Up Caddy on AlmaLinux 10 as a Reverse Proxy with Automatic HTTPS

How to Set Up Caddy on AlmaLinux 10 as a Reverse Proxy with Automatic HTTPS

Caddy is an open-source web server application built using the Go programming language, capable of running on various operating system platforms. First developed in 2015, Caddy continues to evolve into a modern web server designed to meet the diverse requirements of cutting-edge applications. This blog will teach you how to set up Caddy on AlmaLinux 10.

A key advantage of Caddy is its ease of use and simplicity, making it an ideal choice for those who want to run a web server without navigating complex configuration processes. In this article, we will show you how to set up Caddy on AlmaLinux 10 as a reverse proxy with automatic HTTPS.

Prerequisite

Conventions

# – given commands should be executed with root privileges either directly as a root user or by use of sudo command
$ – given commands should be executed as a regular user

Step 1: Log in to your server via SSH

In this tutorial, we are going to use root to install everything and execute commands. So, you need to add ‘sudo’ if you are using your other system user with sudo privileges. First, let’s log in to our AlmaLinux 10 machine.

ssh root@IP_Address -p Port_number

You will need to replace ‘IP_Address’ and ‘Port_number’ with your server’s respective IP address and SSH port number. Additionally, replace ‘root’ with the username of the system user with sudo privileges.

You can check whether you have the proper AlmaLinux version installed on your server with the following command:

# cat /etc/almalinux-release

You will see this output:

[root@almalinux10 ~]# cat /etc/almalinux-release 
AlmaLinux release 10.2 (Lavender Lion)

Step 2: Update the System

Before starting, you have to make sure that all AlmaLinux OS package information about applications installed on the server is up to date. You can do this by running the following commands:

# dnf update

That’s it, the system package information should be updated now.

Step 3. Install Caddy

In this step, we will install Caddy using Fedora COPR. Fedora COPR (Community Projects) is an easy-to-use, community-driven automatic build system that lets users create and host custom package repositories for Fedora, CentOS, RHEL, Rocky Linux, and AlmaLinux. Let’s execute these commands:

# dnf install 'dnf-command(copr)'
# dnf copr enable @caddy/caddy

The copr command is used to add or remove Copr repositories to the local system. The command sudo dnf install ‘dnf-command(copr)’ installs the DNF plugin required to manage Copr repositories on Red Hat Enterprise Linux (RHEL), CentOS Stream, Rocky Linux, AlmaLinux, and Amazon Linux

[root@localhost ~]# dnf copr enable @caddy/caddy
Enabling a Copr repository. Please note that this repository is not part
of the main distribution, and quality may vary.

The Fedora Project does not exercise any power over the contents of
this repository beyond the rules outlined in the Copr FAQ at
<https://docs.pagure.org/copr.copr/user_documentation.html#what-i-can-build-in-copr>,
and packages are not held to any quality or security level.

Please do not file bug reports about these packages in Fedora
Bugzilla. In case of problems, contact the owner of this repository.

Do you really want to enable copr.fedorainfracloud.org/@caddy/caddy? [y/N]: y
Repository successfully enabled.

Finally, we can install Caddy

# dnf install caddy

Once installed, Caddy will not run automatically. We can run it now and configure it to run automatically upon server reboot.

# systemctl enable --now caddy

That’s it! Caddy is now running. It is listening on ports 80 and 2019. Port 2019 is used to host Caddy’s dynamic JSON configuration and control API (/load, /stop, /config/, etc.) rather than a public web dashboard. Let’s check the status now.

# systemctl status caddy

The command above will show you this:

[root@almalinux10 ~]# systemctl status caddy
● caddy.service - Caddy
     Loaded: loaded (/usr/lib/systemd/system/caddy.service; enabled; preset: disabled)
     Active: active (running) since Sat 2026-10-17 08:22:20 WIB; 4min 10s ago
 Invocation: 954de98f534542048eaa09bf5074ff26
       Docs: https://caddyserver.com/docs/
   Main PID: 2385 (caddy)
      Tasks: 7 (limit: 10336)
     Memory: 19.3M (peak: 21.3M)
        CPU: 115ms
     CGroup: /system.slice/caddy.service
             └─2385 /usr/bin/caddy run --environ --config /etc/caddy/Caddyfile

Oct 17 08:22:20 almalinux10 caddy[2385]: {"level":"warn","ts":1792200140.5433805,"logger":"http.auto_https","msg":"server is listening only on the HTTP port, so no automatic HTTPS will be applied to thi>
Oct 17 08:22:20 almalinux10 caddy[2385]: {"level":"info","ts":1792200140.5438795,"logger":"tls.cache.maintenance","msg":"started background certificate maintenance","cache":"0x2ca406d18b80"}
Oct 17 08:22:20 almalinux10 caddy[2385]: {"level":"warn","ts":1792200140.544141,"logger":"http","msg":"HTTP/2 skipped because it requires TLS","network":"tcp","addr":":80"}
Oct 17 08:22:20 almalinux10 caddy[2385]: {"level":"warn","ts":1792200140.5441759,"logger":"http","msg":"HTTP/3 skipped because it requires TLS","network":"tcp","addr":":80"}
Oct 17 08:22:20 almalinux10 caddy[2385]: {"level":"info","ts":1792200140.5441856,"logger":"http.log","msg":"server running","name":"srv0","protocols":["h1","h2","h3"]}
Oct 17 08:22:20 almalinux10 caddy[2385]: {"level":"info","ts":1792200140.5452237,"msg":"autosaved config (load with --resume flag)","file":"/var/lib/caddy/.config/caddy/autosave.json"}
Oct 17 08:22:20 almalinux10 systemd[1]: Started caddy.service - Caddy.
Oct 17 08:22:20 almalinux10 caddy[2385]: {"level":"info","ts":1792200140.5467753,"msg":"serving initial configuration"}
Oct 17 08:22:20 almalinux10 caddy[2385]: {"level":"info","ts":1792200140.5519648,"logger":"tls","msg":"cleaning storage unit","storage":"FileStorage:/var/lib/caddy/.local/share/caddy"}
Oct 17 08:22:20 almalinux10 caddy[2385]: {"level":"info","ts":1792200140.5530741,"logger":"tls","msg":"finished cleaning storage units"}

Step 4. Configure Caddy

Once the Caddy web server is successfully installed, you need to configure a virtual host. This tells the web server to direct a specific domain to a particular path or working directory within the system. Configuring a virtual host in Caddy is quite straightforward; follow these steps:

First, let’s open the configuration file using a text editor (such as nano or vi):

# nano /etc/caddy/Caddyfile

Then, add the following configuration to that file:

yourdomain.com:443 {
# Set this path to your site's directory. 
root * /var/www/yourdomain.com

# Enable the static file server. 
file_server

# Another common task is to set up a reverse proxy:
# reverse_proxy localhost:8080

# Or serve a PHP site through php-fpm:
# php_fastcgi localhost:9000
}

Do not forget to replace yourdomain.com with your actual domain or subdomain name pointing to your server.

Save the file, then exit from the editor.

Now, create the directory for your domain:

# mkdir -p /var/www/yourdomain.com

For testing purposes, you can create an index.html file within the directory you just created:

# nano /var/www/yourdomain.com/index.html

Add any content you like, then save your changes by pressing Ctrl+x, typing y, and pressing Enter.

Adjust the file ownership and permissions:

# chown caddy:caddy /var/www/yourdomain.com/index.html
# chmod 644 /var/www/yourdomain.com/index.html

Finally, reload the Caddy service and then access your domain via a web browser:

# systemctl reload caddy

Step 5. Enable HTTPS

One of the built-in features of the Caddy web server is the automation of HTTPS for domains configured within a virtual host. To activate HTTPS on the Caddy web server, simply run this command:

# caddy trust yourdomain.com

The command will fail if your actual domain name is not pointing to the server. If you just recently pointed your domain to your server, you would want to wait for a few minutes or hours for the DNS update to propagate in your area.

Step 6. Configure Reverse Proxy

In this step, we will configure Caddy to act as a reverse proxy. For example, you want to use Caddy to connect to your NodeJS application on port 3000. Let’s edit the existing yourdomain.com to enable the reverse proxy.

# nano /etc/caddy/Caddyfile

Delete the lines you added in step 4, then insert the following:

Need a fast and easy fix?
✔ Unlimited Managed Support
✔ Supports Your Software
✔ 2 CPU Cores
✔ 2 GB RAM
✔ 50 GB PCIe4 NVMe Disk
✔ 1854 GeekBench Score
✔ Unmetered Data Transfer
NVME 2 VPS

Now just $43 .99
/mo

GET YOUR VPS
yourdomain.com {
        
        reverse_proxy localhost:3000

        # Enable caching for static file extensions
        @cacheableStaticFiles {
                path_regexp \.(jpg|jpeg|png|webp|gif|avif|ico|svg|css|js|gz|eot|ttf|otf|woff|woff2|pdf)$
        }
        header @cacheableStaticFiles Cache-Control "public, max-age=31536000"

        # Log file
        log {
                output file /var/log/caddy/yourdomain.log
                format console
        }

        encode gzip
        # Security headers
        header {
                Server "Caddy"
                -X-Powered-By
                X-Frame-Options "SAMEORIGIN"
                Access-Control-Allow-Methods "GET, POST, OPTIONS"
                X-Content-Type-Options "nosniff"
                Referrer-Policy "no-referrer"
                Access-Control-Max-Age 60000
                Permissions-Policy "microphone=(), geolocation=(self), fullscreen=()"
                Content-Security-Policy "default-src 'self' 'unsafe-inline' 'unsafe-eval' http: https:; img-src 'self' data: https:; font-src 'self' data: https:; frame-src 'self' data: https: blob:"
                X-XSS-Protection "1; mode=block"
        }

        @disallowed {
                path *.sql
                path *.bak
                path *.ini
                path *.log
                path *.conf
                path *.txt
        }
        respond @disallowed 404
}

Save the file, then exit from the editor.

Now, run this command:

# caddy validate --config /etc/caddy/Caddyfile

If everything is okay, we can execute this:

# caddy reload --config /etc/caddy/Caddyfile

Conclusion

That’s it! You should be able to access your NodeJS app at https://yourdomain.com now.

In this tutorial, SELinux is considered disabled. If you encounter an issue, it’s most likely related to SELinux.

If you are one of our web hosting customers and use our managed AlmaLinux Hosting, you don’t have to follow this tutorial and Set Up Caddy on AlmaLinux 10 as a Reverse Proxy with Automatic HTTPS yourself; our experienced Linux administrators will Set Up Caddy on AlmaLinux 10 as a Reverse Proxy with Automatic HTTPS for you. They are available 24×7 and will take care of your request immediately, and all you need to do is to submit a ticket. Configuring Caddy is not just about the installation; we can help you optimize your Caddy web server installation if you have an active service with us.

If you liked this post please share it with your friends or leave a comment below.

Leave a Comment