Dockerized NGINX is not accessed from traefik - Gateway Timeout

Hi!
I am struggling with the problem that the request from traefik does not arrive in NGINX. I get a Gateway Timeout error in my browser. On the console in the log, I do not see any incoming connection from the traffic in the access log.

Everything runs on my VPS. Can anyone tell me what I'm doing wrong?

This is my configurations:

version: '3.9'

services:
  reverse-proxy:
    container_name: satur-reverse-proxy
    image: traefik:v2.9
    ports:
      - "80:80"
    volumes:
      - /var/run/docker.sock:/var/run/docker.sock:ro
    networks:
      - satur-proxy
    command:
      - --global.sendanonymoususage=false
      - --api.dashboard=true
      - --api.insecure=true
      - --log.level=DEBUG
      - --log.filepath=/var/log/traefik.log
      - --accesslog=true
      - --accesslog.filepath=/var/log/traefik-access.log
      - --providers.docker.network=satur-proxy
      - --providers.docker.exposedByDefault=false
      - --entrypoints.web.address=:80
    labels:
      - traefik.enable=true
      - traefik.http.routers.mydashboard.rule=Host(`admin.domain.tld`)
      - traefik.http.routers.mydashboard.service=api@internal
/UJoJgmAk1

networks:
  satur-proxy:
    external: true

app.yaml

version: '3.9'

services:
  app_php:
    container_name: app_php
    build:
      context: ./docker/php
    volumes:
      - .:/var/www/symfony
      - ../cdn/data:/data
      - ~/.ssh:/root/.ssh:ro
    networks:
      - satur-proxy

  app_nginx:
    container_name: app_nginx
    image: nginx:stable-alpine
    labels:
      - traefik.enable=true
      - traefik.http.routers.app.rule=Host(`app.domain.tld`)
      - traefik.http.routers.app.entrypoints=web
      - traefik.http.services.app.loadbalancer.server.port=80
    volumes:
      - .:/var/www/symfony
      - ./docker/nginx/default.conf:/etc/nginx/conf.d/default.conf
    depends_on:
      - app_php
    networks:
      - satur-proxy

networks:
  satur-proxy:
    external: true

nginx.conf

upstream php-upstream {
    server app_php:9000;
}

server {
    listen 80;
    index index.php;
    server_name localhost;
    root /var/www/symfony/public;
    client_max_body_size 20M;

    location / {
        try_files $uri /index.php$is_args$args;
    }

    location ~ ^/index\\.php(/|$) {
        fastcgi_pass php-upstream;
        fastcgi_split_path_info ^(.+\\.php)(/.*)$;
        include fastcgi_params;
        fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
        fastcgi_param DOCUMENT_ROOT $realpath_root;
        internal;
    }

    location ~ \.php$ {
        return 404;
    }

    error_log "/var/log/nginx/error.log" debug;
    access_log /var/log/nginx/project_access.log;
}

"Gateway timeout" usually hapens when the target service is not reachable. Specifically when using Traefik Docker Service Discovery and Traefik does not share the same network with the target service or the target service has multiple networks and docker.network is not set.

Try running a plain nginx container (or whoami) with your settings and see if it's working.

For me an application should always be self-contained, so for experiments with PHP I always use a single container (php:apache) instead of having a web server and PHP in two.

On what port should my other nginx containers run? I have a total of 5. I guess they can't all run at 80:80. Then the question is whether another port needs to be added to the traefic configuration, e.g. 8083 as I have, for example traefic 8080.

Only Traefik needs a port exposed. It will route requests to services/containers by matching Host() and/or PathPrefix() and send it to the service/container internal port.

If no networks are specified, Docker will attach containers to default/bridge. Best practice is to create network(s) and attach containers to it.

See simple example.

The whole problem was that my container was not on the same network. :slight_smile:

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