Not reliably server application

1. Output of caddy version:

v2.6.2 h1:wKoFIxpmOJLGl3QXoo6PNbYvGW4xLEgo32GPBEjWL8o=

2. How I run Caddy:

Docker development php server just localhost to port 80 (http://localhost:80/bridge.php)

a. System environment:

Docker(WSL2)

b. Command:

docker-compose up -d app

c. Service/unit/compose file:

networks:
  listech:
    external: true

services:
  app:
    restart: unless-stopped
    image: caddy:2.6.2-alpine
    volumes:
      - ./src:/var/www/html
      - ./caddy_data:/data
      - ./caddy/Caddyfile:/etc/caddy/Caddyfile
    ports:
      - 8080:80
    extra_hosts:
      # <-- this is required
      - "host.docker.internal:host-gateway"
    depends_on:
      - php
    networks:
      - listech

  php:
    image: lti-php:7.4-fpm-alpine
    build:
      context: .
      dockerfile: ./php.dockerfile
    volumes:
      - ./src:/var/www/html
    networks:
      - default
      - listech

  composer:
    image: lti-composer:2.1.2
    build:
      context: .
      dockerfile: composer.dockerfile
    volumes:
      - ./src:/var/www/html:delegated
    working_dir: /var/www/html
    depends_on:
      - php
    user: lti
    networks:
      - listech
    entrypoint: [ "composer", "--ignore-platform-reqs" ]

d. My complete Caddy config:

{
    auto_https off
    php_fastcgi php:9000
}

3. The problem I’m having:

Caddy not reliably server the application. Sometime it loads fine others I get 404 file not found

4. Error messages and/or full log output:

bridge-app-1 | 
{
    "level": "info",
    "ts": 1666640407.4056754,
    "logger": "http.log.access",
    "msg": "handled request",
    "request": {
        "remote_ip": "172.18.0.1",
        "remote_port": "60286",
        "proto": "HTTP/1.1",
        "method": "GET",
        "host": "localhost:8081",
        "uri": "/bridge.php",
        "headers": {
            "Accept-Language": [
                "en-US,en;q=0.5"
            ],
            "Connection": [
                "keep-alive"
            ],
            "Cookie": [],
            "Upgrade-Insecure-Requests": [
                "1"
            ],
            "Sec-Fetch-Mode": [
                "navigate"
            ],
            "User-Agent": [
                "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:106.0) Gecko/20100101 Firefox/106.0"
            ],
            "Accept": [
                "text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,*/*;q=0.8"
            ],
            "Sec-Fetch-Dest": [
                "document"
            ],
            "Sec-Fetch-Site": [
                "cross-site"
            ],
            "Accept-Encoding": [
                "gzip, deflate"
            ]
        }
    },
    "user_id": "",
    "duration": 0.095870031,
    "size": 10922,
    "status": 200,
    "resp_headers": {
        "Server": [
            "Caddy"
        ],
        "Cache-Control": [
            "no-store, no-cache, must-revalidate"
        ],
        "Pragma": [
            "no-cache"
        ],
        "Expires": [
            "Thu, 19 Nov 1981 08:52:00 GMT"
        ],
        "Content-Type": [
            "text/html; charset=UTF-8"
        ],
        "X-Powered-By": [
            "PHP/7.4.32"
        ]
    }
}
bridge-app-1 | 
{
    "level": "error",
    "ts": 1666640407.9281108,
    "logger": "http.log.access",
    "msg": "handled request",
    "request": {
        "remote_ip": "172.18.0.1",
        "remote_port": "60286",
        "proto": "HTTP/1.1",
        "method": "GET",
        "host": "localhost:8081",
        "uri": "/bridge.php",
        "headers": {
            "Sec-Fetch-Dest": [
                "document"
            ],
            "Sec-Fetch-Site": [
                "cross-site"
            ],
            "User-Agent": [
                "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:106.0) Gecko/20100101 Firefox/106.0"
            ],
            "Accept": [
                "text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,*/*;q=0.8"
            ],
            "Accept-Language": [
                "en-US,en;q=0.5"
            ],
            "Cookie": [],
            "Upgrade-Insecure-Requests": [
                "1"
            ],
            "Connection": [
                "keep-alive"
            ],
            "Sec-Fetch-Mode": [
                "navigate"
            ],
            "Accept-Encoding": [
                "gzip, deflate"
            ]
        }
    },
    "user_id": "",
    "duration": 0.001101462,
    "size": 16,
    "status": 404,
    "resp_headers": {
        "Server": [
            "Caddy"
        ],
        "Status": [
            "404 Not Found"
        ],
        "X-Powered-By": [
            "PHP/7.4.32"
        ],
        "Content-Type": [
            "text/html; charset=UTF-8"
        ]
    }
}

5. What I already tried:

Not really sure what to try

6. Links to relevant resources:

That’s not a valid Caddyfile.

Please review the docs:

1 Like

I was tinkering more afterwords and this is my new Caddyfile but still having the same issue

{
    auto_https off
}

:80 {
    log
    root * /var/www/html
    file_server
    php_fastcgi php:9000
}

The 404 is coming from your PHP application. What is the PHP code?

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