WP Super Cache with Caddy Web Server

Web server market is dominated by Apache HTTP server that enjoys its status because of its open source nature and because of its role in bringing the masses to the world wide web. Without it, we may not have had so many web hosts and web sites. However, its memory footprint has been a concern until today.

Nginx is the second largest in terms of Web Servers Market Share. While Nginx is still open source, the constant upselling of its commercial subscription may not be welcomed by everyone. Don’t get me wrong. I use Nginx too for its low memory footprint and its efficiency in serving static files.

Microsoft’s IIS is third most popular web server. It is rock solid, having its own use cases.

OpenLiteSpeed is very limited in its functionality.

I have always been looking for a truly open source web server (similar to Apache HTTP server), but is written from the ground up to be efficient like Nginx. While, I was searching for a web server that is small in footprint for my MacBook Air, I stumbled upon Caddy Web Server.

Caddy Icon

Caddy is a web server written on Go language (Do you know Docker is based on Go too?). Caddy claims itself as an alternative web server that is unique in being the HTTP/2 server with automatic HTTPS. Automatic HTTPS means it can setup SSL for the sites automatically with the help of LetsEncrypt. Please see the video below to understand how it works.

Caddy is yet to reach 1.0. Yet, it is already feature-rich. For example, the support for automatic HTTPS, HTTP/2, support for virtual hosts including SNI, strong rewrite directive in Caddy including the support for “if” conditions. Caddy doesn’t offer location directive, Upgrades to Caddyfile.

I have been playing around with Caddy for a while in my spare server that hosts “pothi.info” and most things worked fine for me. I am a big fan of WP Super Cache plugin for WordPress and have been using it for almost every site. However, it contains the plenty of htaccess code. Converting all those rules into Caddyfile is going to take a while. However, I made WP Super Cache to work when it uses disk-caching. Here’s the working Caddyfile config…

# let's redirect HTTP connections to HTTPS
www.pothi.info:80, pothi.info:80 {
    tls off
    redir https://pothi.info{uri}

# let's also redirect www.pothi.info to pothi.info
www.pothi.info:443 {
    # tls config here, hidden for obvious reasons!
    redir scheme://pothi.info{uri}

pothi.info:443 {
    # tls config here, hidden for obvious reasons!

    # let's turn on compression

    # similar to root directive in Nginx
    root /path/to/wordpress/

    # send php requests to PHP-FPM
    # unix sockets work too!
    fastcgi / php

    # rewrite is so powerful in Caddy
    rewrite / {
        # similar to try_files in Nginx
        to /wp-content/cache/supercache/{host}{uri}index-https.html {path} {path}/ /index.php?{query}

I wouldn’t accept this as the complete solution. For example, this doesn’t check if the user is logged in. This doesn’t check if the cached content is available for mobile users. Yet, it works. It looks simple.

First visit to the home page, hitting PHP…

First Visit to the home page

The consecutive visit, hitting the cache…

Caddy WPSC cache

As Caddy brings more features and configuration options in its core, I will keep improving the above config to work for mobile users and logged-in users.

Do you like Caddy? Have you ever tried it?

2 Replies to “WP Super Cache with Caddy Web Server”

    1. Hi Vince,

      The entire configuration is based on a single line (to /wp-content/cache/supercache/{host}{uri}index-https.html {path} {path}/ /index.php?{query}). I don’t think there is anything to update in it, unless it doesn’t work for you for some reason. Please feel free to post here if it didn’t work. Thanks.

Leave a Reply

Your email address will not be published. We use cookies to prevent spam comments. Required fields are marked *