Kirby 3 and Caddy 2 : Caddyfile

Hi,

I try to run on my local machine Caddy Server 2 with Kirby 3 using the Caddyfile.
I use PHP 8 and php-fpm. All the Kirby PHP extensions required by Kirby are installed.

I found this post Caddy v2 file for Kirby 2 & Kirby 3 on local sites - Wiki - Caddy Community and use the Caddyfile made by @WoofDog but I meet some trouble when navigating on the panel. I get this error message most of the time :

The JSON response from the API could not be parsed

This is my Caddyfile inspired from @WoofDog’s Caddyfile :

(common) {
  encode gzip
  php_fastcgi unix//run/php-fpm/php-fpm.sock php
  tls internal
  file_server
  header * {
    X-Frame-Options "DENY"
    X-XSS-Protection "1; mode=block"
    X-Content-Type-Options "nosniff"
    X-Frame-Options "SAMEORIGIN"
  }

}

(kirby) {
  @blocked {
    path *.txt *.md *.mdown
  }
  redir @blocked /
}

:2015 {
    import common
    import kirby
    root * /home/xxxxxx/Documents/App/my_app/
}

Does anyone use Kirby 3 and Caddy 2 and could share its Caddyfile ?

Your config looks good.

Could you please take a look at your browser’s dev console and check if the API responses actually contain JSON? Sometimes the API requests are routed incorrectly, so the responses may contain HTML etc.

Please post a screenshot of the /api/system response, which is the first request the Panel makes.

@lukasbestle Thanks for your help

This is the error output by my terminal :

ERROR   http.log.error  dialing backend: dial tcp: lookup php: no such host
{
  "request": {
    "remote_addr": "127.0.0.1:35392",
    "proto": "HTTP/1.1",
    "method": "GET",
    "host": "localhost:2015",
    "uri": "/",
    "headers": {
      "User-Agent": [
        "Mozilla/5.0 (X11; Linux x86_64; rv:86.0) Gecko/20100101 Firefox/86.0"
      ],
      "Accept-Encoding": [
        "gzip, deflate"
      ],
      "Cookie": [
        "kirby_session=fa3a1e04b2fe691fca6874bcfacc09be41a5d520%2B1614770752.57f29285dd9970a8d43f.d31af3ae308c22192fb2e541ded93bb71de64795477deb5e4e4bd45b4a676d29"
      ],
      "Upgrade-Insecure-Requests": [
        "1"
      ],
      "Cache-Control": [
        "max-age=0"
      ],
      "Accept": [
        "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8"
      ],
      "Accept-Language": [
        "en-US,en;q=0.5"
      ],
      "Connection": [
        "keep-alive"
      ]
    }
  },
  "duration": 0.042280157,
  "status": 502,
  "err_id": "wf2ycsp34",
  "err_trace": "reverseproxy.statusError (reverseproxy.go:783)"
}

And this is the screenshot of my dev console :

Ah! Try removing the php at the end of the php_fastcgi line. That line should end in .sock.

You’re right, ! Thx
I’ve removed the last php word on this line and restart Caddy but I have a white page now on the homepage and the panel page. I’ve checked the .sock path and found that my /run/php-fpm folder is empty, no php-fpm.sock file.

I did a big update few days ago on my Linux System, the PHP version must have been upgraded > yes PHP 8.0.2 run on my laptop now.

I’m looking for where is the php-fpm.sock …

Take a look at your php-fpm.log to see if it has problems starting up. Maybe php-fpm isn‘t running at all, in which case you need to start its system service.

I restarted all my services, adapt and run caddy and it works now !
Thank you very much @lukasbestle

This is my final Caddyfile version for those who are interested (Kirby 3, Caddy 2.0.3, PHP 8.0.2, php-fpm)

(common) {
  encode gzip
  php_fastcgi unix//run/php-fpm/php-fpm.sock
  tls internal
  file_server
  header * {
    # You may want some other header options...
    X-Frame-Options "DENY"
    X-XSS-Protection "1; mode=block"
    X-Content-Type-Options "nosniff"
    X-Frame-Options "SAMEORIGIN"
  }

}

(kirby) {
  @blocked {
    path *.txt *.md *.mdown
  }
  redir @blocked /
}

:2015 {
    import common
    import kirby
    root * /home/username/Documents/App/my_app/
}
1 Like