Docker – nginx with php-fpm connection refused

I have problem with my docker container, this i my docker-compose

version: '3.7'

services:
  app:
    container_name: ${APP_NAME}_app
    build:
      context: ./docker/app
      args:
        - timezone=${TZ}
        - xdebug=${XDEBUG}
    volumes:
      - ./srv/server:/srv:cached
      - ./srv/server/var/log:/srv/var/log:cached
    restart: unless-stopped
    secrets:
      - host_ssh_key
      - known_hosts
  nginx:
    container_name: ${APP_NAME}_nginx
    build:
      context: ./docker/nginx
      args:
        - nginx_host=local.docker
    volumes:
      - ./srv/server/var/log:/var/log/nginx:cached
      - ./srv/server:/srv:cached
      - ./docker/nginx/default.conf:/etc/nginx/conf.d/default.conf
    links:
      - app
    restart: unless-stopped
    ports:
      - 80:80
      - 443:443
    expose:
      - "80"
      - "443"
    init: true
    tty: true
    #network_mode: host
    networks:
      - api-network
      - default

my virtualhost on nginx

server {
    listen 80;
    server_name local.docker;

    root /srv/public;

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

    location ~ ^/.+.php(/|$) {
        if ($request_method = 'OPTIONS') {
            add_header 'Access-Control-Allow-Origin' "*" always;
            add_header 'Access-Control-Allow-Methods' 'GET, POST, PATCH, PUT, DELETE, OPTIONS' always;
            add_header 'Access-Control-Allow-Headers' 'Content-Type, Accept, Authorization' always;
            add_header 'Access-Control-Allow-Credentials' 'true' always;

            add_header Access-Control-Max-Age 1728000;
            add_header Content-Type 'text/plain charset=UTF-8';
            add_header Content-Length 0;
            return 204;
        }

        if ($request_method ~ '(GET|POST|PATCH|PUT|DELETE)') {
            add_header Access-Control-Allow-Origin "*" always;
            add_header Access-Control-Allow-Methods 'GET, POST, PATCH, PUT, DELETE, OPTIONS' always;
            add_header Access-Control-Allow-Headers 'Content-Type, Accept, Authorization' always;
            add_header Access-Control-Allow-Credentials true always;
        }
        
        fastcgi_read_timeout 240;
        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;
    }

    location ~ .css {
        add_header  Content-Type    text/css;
    }
    location ~ .js {
        add_header  Content-Type    application/x-javascript;
    }

    error_log /var/log/nginx/app_error.log;
    access_log /var/log/nginx/app_access.log;
}

upstream config
/etc/nginx/conf.d/upstream.conf

upstream php-upstream { server app:9000; }

When i run docker-composer i don’t have any problem, but when I open browser with vhost url i have 502 Bad Gateway. In logs i have this

2020/10/23 19:34:31 [error] 28#28: *1 connect() failed (111: Connection refused) while connecting to upstream, client: 172.19.0.1, server: local.docker, request: "GET / HTTP/1.1", upstream: "fastcgi://172.18.0.10:9000", host: "local.docker"
2020/10/23 19:34:32 [error] 28#28: *1 connect() failed (111: Connection refused) while connecting to upstream, client: 172.19.0.1, server: local.docker, request: "GET / HTTP/1.1", upstream: "fastcgi://172.18.0.10:9000", host: "local.docker"

I’ve been trying to fix it for several hours, checking different solutions, but it doesn’t work, I don’t know where the problem is.

Source: Docker Questions