The caddy in the container has an error that it cannot read index.php

1. Caddy version (caddy version):

Caddy V2

2. How I run Caddy:

Use podman.

a. System environment:

Fedora 35 Server
Podman 3.4.7

b. Command:

podman-compose start

c. Service/unit/compose file:

version: '3.3'
services:
  wordpress:
    network_mode: mybridge
    container_name: wordpress
    volumes:
      - '/home/yuxianglin/wordpress_v/html:/var/www/html'
    image: 'wordpress:fpm'

  caddy:
    network_mode: mybridge
    ports:
      - '80:80'
      - '443:443'
    container_name: caddy
    volumes:
      - '/home/yuxianglin/wordpress_v/html:/var/www/wordpress'
      - '/home/yuxianglin/caddy_v/Caddyfile:/etc/caddy/Caddyfile'
      - '/home/yuxianglin/caddy_v/data:/data'
    image: 'caddy:latest'

d. My complete Caddyfile or JSON config:

sub.example.com {
        root * /var/www/wordpress
        php_fastcgi wordpress:9000
        file_server
}

3. The problem I’m having:

When Chrome visits sub.example.com, file not found.

4. Error messages and/or full log output:

The container caddy did not give errors. The container wordpress threw an error.

wordpress logs:

[10-May-2022 12:40:20] NOTICE: Finishing ...
[10-May-2022 12:40:20] NOTICE: exiting, bye-bye!
[10-May-2022 13:05:43] NOTICE: fpm is running, pid 1
[10-May-2022 13:05:43] NOTICE: ready to handle connections
10.89.4.3 -  10/May/2022:13:06:16 +0000 "GET /index.php" 404
10.89.4.3 -  10/May/2022:13:06:16 +0000 "GET /index.php" 404
10.89.4.3 -  10/May/2022:13:06:40 +0000 "GET /index.php" 404

5. What I already tried:

When I enter the container caddy, run the command:

/srv # ls /var/www/wordpress -l
total 220
-rw-r--r--    1 xfs      xfs            405 Feb  6  2020 index.php
-rw-r--r--    1 xfs      xfs          19915 Jan  1 00:15 license.txt
-rw-r--r--    1 xfs      xfs           7437 Dec 28 17:38 readme.html
-rw-r--r--    1 xfs      xfs           7165 Jan 21  2021 wp-activate.php
drwxr-xr-x    9 xfs      xfs           4096 Apr  5 19:13 wp-admin
-rw-r--r--    1 xfs      xfs            351 Feb  6  2020 wp-blog-header.php
-rw-r--r--    1 xfs      xfs           2338 Nov  9 23:07 wp-comments-post.php
-rw-rw-r--    1 xfs      xfs           5480 Apr 21 12:39 wp-config-docker.php
-rw-r--r--    1 xfs      xfs           3001 Dec 14 08:44 wp-config-sample.php
drwxr-xr-x    4 xfs      xfs             52 Apr  5 19:13 wp-content
-rw-r--r--    1 xfs      xfs           3939 Aug  3  2021 wp-cron.php
drwxr-xr-x   26 xfs      xfs          12288 Apr  5 19:13 wp-includes
-rw-r--r--    1 xfs      xfs           2496 Feb  6  2020 wp-links-opml.php
-rw-r--r--    1 xfs      xfs           3900 May 15  2021 wp-load.php
-rw-r--r--    1 xfs      xfs          47916 Jan  4 08:30 wp-login.php
-rw-r--r--    1 xfs      xfs           8582 Sep 22  2021 wp-mail.php
-rw-r--r--    1 xfs      xfs          23025 Nov 30 17:32 wp-settings.php
-rw-r--r--    1 xfs      xfs          31959 Oct 25  2021 wp-signup.php
-rw-r--r--    1 xfs      xfs           4747 Oct  8  2020 wp-trackback.php
-rw-r--r--    1 xfs      xfs           3236 Jun  8  2020 xmlrpc.php

There is index.php here, but wordpress says it can’t find index.php. And the root path is also defined in the Caddyfile.

You’re using a different root in the Caddy container vs the Wordpress container. They need to match, or you need to override the root subdirective of php_fastcgi to tell it what root it uses in the other container.

So I should modify my Caddyfile, change to this

blog.yuxianglin.top {
        php_fastcgi wordpress:9000 {
                root * /var/www/wordpress
        }
        file_server
}

But I am getting an error from caddy:

{"level":"info","ts":1652190998.0577936,"msg":"using provided configuration","config_file":"/etc/caddy/Caddyfile","config_adapter":"caddyfile"}
run: adapting config using caddyfile: parsing caddyfile tokens for 'php_fastcgi': /etc/caddy/Caddyfile:4 - Error during parsing: unrecognized subdirective /var/www/wordpress

Either change this to use /var/www/wordpress (on the wordpress container)

Or change this (and your Caddyfile) to use /var/www/html (on the caddy container):

Or change your Caddyfile to this:

sub.example.com {
	root * /var/www/wordpress
	php_fastcgi wordpress:9000 {
		root /var/www/html
	}
	file_server
}

Note that you don’t use a * when using root as a subdirective – it doesn’t take an optional matcher token, like directives do.

2 Likes

Thank you, it’s working!

1 Like

This topic was automatically closed after 30 days. New replies are no longer allowed.