Caddy on Host, Wordpress in Container fpm

1. Caddy version (caddy version):

v2.2.1 h1:Q62GWHMtztnvyRU+KPOpw6fNfeCD3SkwH7SfT1Tgt2c=

2. How I run Caddy:

from service caddy start

a. System environment:

Linux mobydick 4.9.0-13-amd64 #1 SMP Debian 4.9.228-1 (2020-07-05) x86_64 GNU/Linux

b. Command:

paste command here

d. My complete Caddyfile or JSON config:

mgmt.hasi.pl {
        log {   
                output file /var/log2/services_mgmt.log {
                        roll_size 1gb
                        roll_keep 5
                        format single_field common_log
                }

        }

        root * /opt/wordpress/wp
        php_fastcgi 0.0.0.0:9005
        encode gzip
        file_server
}


docker-compose.yml

version: '3.1'

services:

  wordpress:
    image: wordpress:fpm
    restart: always
    ports:
            - 0.0.0.0:9005:9000
    environment:
      WORDPRESS_DB_HOST: db
      WORDPRESS_DB_USER: exampleuser
      WORDPRESS_DB_PASSWORD: examplepass
      WORDPRESS_DB_NAME: exampledb
    volumes:
      - /opt/wordpress/wp:/var/www/html

  db:
    image: mysql:5.7
    restart: always
    environment:
      MYSQL_DATABASE: exampledb
      MYSQL_USER: exampleuser
      MYSQL_PASSWORD: examplepass
      MYSQL_RANDOM_ROOT_PASSWORD: '1'
    volumes:
      - db:/var/lib/mysql

volumes:
  wordpress:
  db:

5. What I already tried:

6. Links to relevant resources:

3. The problem I’m having:

Wordpress not loading.

4. Error messages and/or full log output:

wordpress_1 | 192.168.5.1 - 14/Jan/2021:19:00:45 +0000 “GET /index.php” 404

The Problem iam having is that i always get an 404 if i try to access the site.

if i try to load readme.html it does work. but not the wp-admin/install.php nor index.php.

The normal procedure would be to run Caddy within the same docker-compose setting and share a unix socket, but i need Caddy 2 to do also some reverse proxy stuff for my other hosts.

Thanks in Advance

0.0.0.0 isn’t a real IP address. I think you probably mean to use 127.0.0.1

Also, the absolute file paths need to match for both Caddy and php-fpm. If they have different roots, then things won’t work, because php-fpm will be looking in /opt/wordpress/wp in the container, but there will be nothing there.

Why don’t you run Caddy as a docker container? That’ll be much simpler. Mount your /opt/wordpress/wp:/var/www/html volume on both Caddy and your php-fpm container, and use php_fastcgi wordpress:9000 in your Caddyfile instead.

See the docs: Docker Hub

This should work though – perhaps it depends on the system – but it’s basically the same as using :9005, except IPv4 only.

Thanks, that was the cause, caddy served readme.html right, put on php files it sent the wrong path (if you see it from inside/outside Container view.

Thanks again, And thanks for this awesome Webserver.

2 Likes

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