Caddyfile for Kirby 3?

Hi,
I’m trying to test out whether I can get Kirby 3 to run on the Caddy web server, as I am currently running a Kirby 2 website through Caddy and want to upgrade. Do you provide an example Caddyfile (like .htaccess but for Caddy), as I am unable to access the panel with my current Caddyfile which worked for my Kirby 2 setup. I am using a slightly modified version of the Caddyfile example that is now 2 years old from https://github.com/caddyserver/examples/tree/master/kirby, and I understand that Kirby 3 supports Caddy as a web server as stated in this page: https://getkirby.com/docs/guide/installation#requirements

I have all the php requirements too

Any help would be appreciated!

Hi Daniel @dli417

This is a very basic Kirby 3 Caddyfile for a local staging installation:
Do not use it in production!

The rewrite rules should be the lines you are interested in.
In this Caddyfile, I suppose the server use php-fpm 7.2 with unix socket.
Php errors are output directly in your browser.

localhost:2019 {

	tls off

        # PHP-FPM with Unix socket
	fastcgi / /run/php/php7.2-fpm.sock php

	log stdout
	errors visible

	rewrite / {
	    to {path} {path}/ /index.php?{query}
	}

}

Does it help?

1 Like

Hi @gillesvauvarin,

Thanks for the speedy reply! Ive tried it out and YES it works!
I will fiddle around with my Caddyfile and try to incorporate your rewrite rules.

I will leave this question open for now, as I would like to see if Kirby staff have any opinions on this matter.

hi @gillesvauvarin & @dli417!
how would you approach using caddy for a production environment?

I’m thinking about whether it would be smart to create an apache/php container with docker-compose that i would reverse-proxy using caddy, because i have other apps running on the server as well…

@bruno I use Caddy in production as the main web server with php-fpm. I never try to use Caddy as a reverse-proxy but I now it’s possible.

I’m not very familiar with Docker so I have no feedback :-/

I just posted this Caddy v2 Caddyfile (with the help of the people on the Caddy forum) for Kirby 2 and Kirby 3 and am using it locally on my Mac, its’ modular and so easily configurable and it may help… seems to work well.

4 Likes

I am curious as well. What is it that is missing to make any of this usable for production? Just looking at the warning not to use the caddyfile in it’s current state for production. I don’t know anything about the configurations myself.

Hi dracmas which ‘warning not to use the caddyfile’ are you refering?

I was looking at it from someone that doesn’t know how to run the server side to get Kirby running. The beginning of this topic had a warning not to use on a production server so it made me wonder what settings for the config file were needed to configure this properly for exposing traffic to the web.

Honestly considering this if my friend that helps me with NGINX can’t figure out how to get that fixed since this looks like it’s working already.

Yes it seems to work fine locally… I guess the main things you may want to consider for a Caddy live site would be proper SSL certificates rather than the local ones I have in my Caddyfile example. See the Caddy website for more information.

For nginx with K3 we use the file below locally - but again it should be fine for a live site if you add the proper certificate stuff for SSL etc.

# shoes for industry nginx conf for Kirby 3 CMS
# 2020/04/17
# shoesforindustry.net
# Local OSX - No SSL/Certs 
# v 0.0.3

# www.domain.test 
server {
  listen 80;
  server_name www.domain.test;
  access_log  off;
  # Redirect to the non-www host (declared below)
  return 301 http://$host$request_uri;
}

# domain.test
server {
  listen 80;
  server_name  domain.test;
  root       /PATH_TO_SITE/domain;
  access_log  off;
  error_log  /usr/local/etc/nginx/logs/error.log crit;

  add_header X-Frame-Options SAMEORIGIN;
  add_header X-Content-Type-Options nosniff;
  add_header X-XSS-Protection "1; mode=block";

  add_header "Cache-Control" "no-transform";

  # Character Set
  charset UTF-8;

  # php
  location ~\.php$ {
    include   /usr/local/etc/nginx/conf.d/php-fpm;
  }

  # block content
  location ~ ^/content/(.*).(txt|md|mdown)$ {
    rewrite ^/content/(.*).(txt|md|mdown)$ /error redirect;
  }

  # block all files in the site folder from being accessed directly
  location ~ ^/site/(.*)$ {
    rewrite ^/site/(.*)$ /error redirect;
  }

  # block all files in the kirby folder
  location ~ ^/kirby/(.*)$ {
    rewrite ^/kirby/(.*)$ /error redirect;
  }

  # site links
  location / {
    try_files $uri $uri/ /index.php;
  }
  
  # Error pages
  error_page  404     /error;
  error_page  403     /error;

}

You guys have been awesome with examples on how to get Kirby running regardless of what people decide to use.

I only hope there is some way I can also help give back to the community here after I learn more about how everything works using Kirby.