Can't aceesss php:7.4.27-apache through traefik

Hi,

I have docker 20.10.12 runing.
There is a container traefik runing traefik:latest - several containers are using this trafik container successfully.

Now I would like to run a php-script.
Therefor I set up a container test1 runing php:7.4.27-apache (see docker-compose.yml below).
I have a very simple testfile index.html in ./www

File: docker-compose.yml

version: '3' 
services: 
  test1: 
    image: php:7.4.27-apache 
    container_name: test1
    restart: unless-stopped 
    volumes: 
      - ./www:/var/www/html 
      - ./log:/var/log
    labels: 
      - "traefik.enable=true" 
      - "traefik.http.routers.test1.entrypoints=http" 
      - "traefik.http.routers.test1.rule=Host(`test1.xxx.de`)" 
      - "traefik.http.middlewares.test1-https-redirect.redirectscheme.scheme=https" 
      - "traefik.http.routers.test1.middlewares=test1-https-redirect" 
      - "traefik.http.routers.test1-secure.entrypoints=https" 
      - "traefik.http.routers.test1-secure.rule=Host(`test1.xxx.de`)" 
      - "traefik.http.routers.test1-secure.tls=true" 
      - "traefik.http.routers.test1-secure.tls.certresolver=http" 
      - "traefik.http.routers.test1-secure.service=test1" 
      - "traefik.http.services.test1.loadbalancer.server.port=3000" 
      - "traefik.docker.network=proxy" 
      - "traefik.http.routers.test1-secure.middlewares=secHeaders@file" 
    networks: 
      - proxy
networks: 
  proxy: 
    external: true

The container test1 seems to start nomal.
There is no error in traefik-dashboard.
But going to test1.xxx.de only gives me “Bad Gateway” (or “404 page not found” when container test1 is stoped).

I am a little bit lost - why can’t I access the testfile index.html via webbrowser.
Is there any configuration missing?

Thanks Xavier

Hi

Any errors on the traefik side? ( logs )

As I don’t use traefik, I tried it before writing anything. It works for me, except I didn’t configure TLS certs for the container and didn’ forward port 443 to traefik so when it redirected me to the HTTPS version, I got connection refused.

Bad Gateway indicates that traefik cannot reach the service in the container. For example when your service is running on port 8888 but traefik try to use port 80, or everything is listening on the right port and right IP address but traefik is on a different docker network. In that case traefik may know that a container started, but so it try to forward requests (this is why it is not 404 not found) but cannot see the service port.

I would have suggested to check traefik logs as well as Martin did, but I tried and didn’t show anything, so I checked the traefik documentation instead and tried this command to see error messages:

curl -s 127.0.0.1:8080/api/rawdata | jq .

Or if you don’t have jq

curl -s 127.0.0.1:8080/api/rawdata

Both commands requires that you enabled the api on port 8080
This is where I found the example I used: Basic Example - Traefik

My current error message:

    "test1-secure@docker": {
      "entryPoints": [
        "https"
      ],
      "middlewares": [
        "secHeaders@file"
      ],
      "service": "test1",
      "rule": "Host(`test1.xxx.de`)",
      "tls": {
        "certResolver": "http"
      },
      "error": [
        "middleware \"secHeaders@file\" does not exist"
      ],
      "status": "disabled",
      "using": [
        "https"
      ]
    },

but port 80 works on the http entrypoint.