Caddy is a web server designed for modern web applications. Caddy is simple to configure and has automatic Let's Encrypt, so your websites are always secure by default. It is the author's go-to web server.
Here is a short rundown of Caddy's features:
A basic web server
A reverse proxy for directing traffic to multiple sites
Modules for many workloads, including TCP, SSH, and more
A built-in load balancer for managing traffic to multiple websites
Built-in, automated Let's Encrypt support
An API to re-configure the server programmatically
If you try to view a web page at your machine’s IP address or domain name from another computer, you will probably get nothing. That will be the case if you have a firewall up and running.
To open up the necessary ports to actually "see" your web pages, you will use Rocky Linux's built-in firewall, firewalld. The firewalld command for doing this is firewall-cmd.
To open up the http and https services, the services that handles web pages, run:
The -–permanent flag tells the firewall to apply this configuration every time the firewall restarts, and when the server restarts.
–-zone=public tells the firewall to allow incoming connections to this port from everyone.
Lastly, --add-service=http and --add-service=https tells firewalld to pass all HTTP and HTTPS traffic to the server.
These configurations won’t take effect until you force the issue. To do that, tell firewalld to reload its configurations:
sudofirewall-cmd--reload
Note
Now, there is a very small chance that this will not work. In those rare cases, make firewalld do your bidding with the old turn-it-off-and-turn-it-on-again.
systemctlrestartfirewalld
To ensure allowance of the ports, run firewall-cmd --list-all. A properly-configured firewall will look a bit like this:
Unlike traditional web servers like Apache and Nginx, Caddy's configuration format is significantly simpler. Gone are the days where you had to configure the nitty-gritty, like your web server's threading model or SSL certificates, unless you want to.
To edit the Caddy configuration file:
vim/etc/caddy/Caddyfile
A minimum static web server configuration can be similar to this:
As mentioned earlier, Caddy supports FastCGI support for PHP. The good news is that unlike Apache and Nginx, Caddy handles PHP file extensions automatically.
To install PHP, first add the Remi repository (note: if you are running Rocky Linux 8.x, substitute in 8 next to the "release-" below):
The basic installation and configuration of Caddy is incredibly easy. Gone are the days when you spent hours configuring Apache. Yes, Nginx is certainly an improvement, but it still lacks modern but essential features such as Let's Encrypt and Kubernetes ingress support that Caddy builds in, whereas on Nginx (and Apache) you must add them separately.
I've been using Caddy since 2019 as my go-to web server, and it's just so good. In fact, whenever I deal with Apache, Nginx or IIS, it's almost like taking a time machine back to 2010 or earlier.