Trying to make fast_cgi and sockets work but 404 Errors popup

Currently I’m using a 9000 to php-fpm connection, but I would prefer to do it via file sockets and I’m not sure what’s going on

This is my current working Caddyfile

fedoradomain.com {
        root * /usr/share/caddy/wordpress/fedora
        encode gzip zstd

        log {
                output file /var/log/caddy/fedora.log
        }

        @canonicalPath {
                file {
                        try_files {path}/index.php
                }
                not {
                        path */
                }
        }
        @phpFiles {
                path *.php
        }
        route {
                redir @canonicalPath {path}/ 308
                try_files {path} {path}/index.php index.php
                reverse_proxy @phpFiles {
                        to wordpress-fedora:9000
                        transport fastcgi {
                                split .php
                                root /var/www/html
                        }
                }
                respond /uploads/*.php 404
                file_server
        }
}

I’m doing everything with Docker containers and docker compose

For the php-fpm service part, I have this (wordpress:fpm is essentially a php8.2-fpm image just in case):

wordpress-fedora:
    image: wordpress:fpm
    container_name: wordpress-fedora
    restart: unless-stopped
    depends_on:
      - mysql
      - caddy
    volumes:
      - $PWD/volumes/wordpress/fedora:/var/www/html
      - $PWD/wordpress/php.ini:/usr/local/etc/php/conf.d/custom.ini
    env_file:
      - $PWD/mysql/wordpress-fedora.env

And in the caddy service:

caddy:
    image: caddy:latest
    container_name: caddy
    restart: unless-stopped
    volumes:
      - $PWD/volumes/caddy/data:/data/caddy
      - $PWD/volumes/caddy/config:/config
      - $PWD/volumes/wordpress/fedora:/usr/share/caddy/wordpress/fedora
      - $PWD/caddy/Caddyfile:/etc/caddy/Caddyfile
    ports:
      - 80:80
      - 443:443

So far, so good.

Now I’m going to explain what I’m trying to perform with the file socket parts

For the Caddyfile I’m going to simplify it to the max:

fedoradomain.com {
        root * /usr/share/caddy/wordpress/fedora
        encode gzip zstd

        log {
                output file /var/log/caddy/fedora.log
        }

        php_fastcgi unix//run/php/php-fpm-fedora.sock
        file_server
}

And for the Docker Composer part, in the PHP-FPM I simply add two volumes:

 - $PWD/volumes/sockets:/run/php/
 - $PWD/wordpress/www.conf:/usr/local/etc/php-fpm.d/zz-docker.conf

In the zz-docker.conf file I simply switch the port 9000 to the file socket

And in the Caddy part:

- $PWD/volumes/sockets:/run/php/

Now, theoretically Caddy should be reading the socket @ /run/php/php-fpm-fedora.sock and must be able to manipulate it.

I can check in the Caddy container, and the /run/php/php-fpm-fedora.sock at least is there

But I only receive 404 errors.

Remember that with the previous confs, everything works well, so all files and that are in place. Its just that I’m trying to switch from port 9000 to sockets but I’m not having any success :frowning:

PS: This is the www.conf for the PHP-FPM just in case could be relevant:

[global]
daemonize = no

[www]
listen = /run/php/php-fpm-fedora.sock
listen.mode = 0666

I think you should order file_server before reverse_proxy

Thanks for the idea, but it did not change anything.

But then I realized I’m totally tard, while making the change you proposed, I noted that I was missing the first letter of the hostname… It’s weird, but occasionally, we are so focused and blind on a mistake and the next day we spot it immediately.

Moreover, I’m coming from Nginx, and I’m still familiarized with logs, I’m finding a hard time reading them to spot any mistakes of issues :frowning:

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