简体   繁体   English

docker-compose、caddy 和 php-fpm 的基本配置

[英]base config for docker-compose, caddy and php-fpm

I'm trying to build a base config with caddy and php-fpm on docker-compose. Problem is, I get a "404 file not found" when I try to reach for my index.php file.我正在尝试在 docker-compose 上使用 caddy 和 php-fpm 构建基本配置。问题是,当我尝试访问我的index.php文件时,出现“404 文件未找到”。 Here is my config.这是我的配置。

docker-compose.yml docker-compose.yml

version: "3.8"

services:
  caddy:
    image: caddy:alpine
    ports:
      - "80:80"
      - "443:443"
      - "443:443/udp"
    volumes:
      - $PWD/Caddyfile:/etc/caddy/Caddyfile
      - $PWD/www:/srv/www
      - $PWD/caddy/data:/data
      - $PWD/caddy/config:/config
      - $PWD/caddy/log:/var/log
    depends_on:
      - app
  app:
    image: php:fpm-alpine
    ports:
      - "9000:9000"
    volumes:
      - "$PWD/www:/var/www/html"

Caddyfile Caddy文件

localhost:80 {
    root * /srv/www
    php_fastcgi app:9000
    file_server
}

Finally I have a www folder containing index.php and test.html - http://localhost/test.html works, but http://localhost/index.php gives me a 404.最后我有一个包含index.phptest.html - http://localhost/test.html 的www文件夹,但是 http://localhost/index.php 给了我一个 404。

What am I doing wrong?我究竟做错了什么?

EDIT: here is what I tried:编辑:这是我尝试过的:

  • I checked that I can ping from one container to the other我检查了我是否可以从一个容器 ping 到另一个容器
  • port 9000 is effectively opened on the php container 9000 端口在 php 容器上有效打开

It looks like the php files are not mounted at the right place inside the php container, but /var/www/html is the WorkingDir.看起来 php 文件没有安装在 php 容器内的正确位置,但/var/www/html是 WorkingDir。

I don't know where to go next to troubleshoot this.我不知道旁边的 go 在哪里可以解决这个问题。

Finally, I found the answer!终于,我找到了答案!

php-fpm needs the absolute path of the file, so you either have to have the same path in both containers or add a root directive inside the php_fastcgi block. php-fpm 需要文件的绝对路径,因此您要么必须在两个容器中使用相同的路径,要么在 php_fastcgi 块中添加一个root指令。

localhost:80 {
    root * /srv/www
    encode gzip
    php_fastcgi php:9000 {
        root /var/www/html
    }
    file_server
    log
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM