Switching From Nginx To Caddy

Posted on

I am a long time user of Apache, it was the first web server software I learned to use and therefore it felt like a no brainer to always use it. However over the past year I have started using Nginx more and more. It felt foreign at first but once you get a hang of how to configure new hosts and do the initial setup it’s really just as easy to use as Apache and in my current opinion, much better when it comes to memory usage and the amount of requests it can handle. If you want to read more about the differences you can read this post from tutsplus that describes the pros and cons of using either one for a wordpress website (generally the things discussed here applies to most other applications).

There you have some background information, so what’s Caddy and why should I switch to it? Caddy is written in go and is much easier to use compared to Nginx or Apache but I would not claim that it’s better than either of these. There is a pretty good article describing the differences of Nginx and Caddy here. So why use it? Well with Nginx I have the main configuration file and an additional host file. Here is a full example configuration from the Nginx docs.

So let’s take a look at Caddy, here is what my config file might look like if I was setting up a Laravel website.

example.com {
    root ./public
    fastcgi / php
    rewrite {
        to {path} {path}/ /index.php?{query}

That’s it. That’s all the configuration I need to write to get my Laravel site up and running. If I want to add another host on my Caddy server I can simply add another host under this one with the same structure.

The best part is you can automatically download, verify and configure ssl certificates from Let’s Encrypt for any domain as long as the domain already points to your server.

Caddy is written in go and supports plugins. To install plugins simply download the Caddy source and import your plugins, you can find a list of plugins on the Caddy forums.

Got Something To Say?

Your email address will not be published. Required fields are marked *