title: Docker, Symfony nginx/php-fpm initialized very slow
body: <p>Using this project/Docker setup:
  <a href="https://gitlab.com/martinpham/symfony-5-docker" rel="nofollow noreferrer">https://gitlab.com/martinpham/symfony-5-docker</a></p>
  
  <p>When I do <code>docker-compose up -d</code> I have to wait about 2-3 minutes to actually get it working.
  Before it loads, it gives me "502 Bad Gateway" and logs error:</p>
  
  <pre><code>2020/05/10 09:22:23 [error] 8#8: *1 connect() failed (111: Connection refused) while connecting to upstream, client: 172.28.0.1, server: localhost, request: "GET / HTTP/1.1", upstream: "fastcgi://172.28.0.3:9000", host: "localhost"
  </code></pre>
  
  <p>Why nginx or php-fpm or smth else is loading so slow ?
  It's my first time using nginx and Symfony. Is it something normal ? I expect it to be loaded max in 1-2 second, not 2-3 minutes.</p>
  
  <p>Yes, I have seen similar issues, but not appropriate solutions for me.
  Some nginx/php-fpm/docker-compose configuration should be changed - I tried, but no luck.
  I modified a little bit <em>nginx/sites/default.conf</em> (just added xdebug stuff)</p>
  
  <pre><code>server {
      listen 80 default_server;
      #listen [::]:80 default_server ipv6only=on;
  
      server_name localhost;
  
      root /var/www/public;
      index index.php index.html index.htm;
  
      location / {
           try_files $uri $uri/ /index.php$is_args$args;
      }
  
      location ~ \.php$ {
          try_files $uri /index.php =404;
          fastcgi_pass php-upstream;
          fastcgi_index index.php;
          fastcgi_buffers 4 256k;
          fastcgi_buffer_size 128k;
          fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
          #!!!!fixes timeouts
          fastcgi_read_timeout 600;
          include fastcgi_params;
  
          fastcgi_param PHP_VALUE "xdebug.remote_autostart=1
          xdebug.idekey=PHPSTORM
          xdebug.remote_enable=1
          xdebug.remote_port=9001
          xdebug.remote_host=192.168.0.12";
      }
  
      location ~ /\.ht {
          deny all;
      }
  
      location /.well-known/acme-challenge/ {
          root /var/www/letsencrypt/;
          log_not_found off;
      }
  }
  </code></pre>
  
  <p>nginx/conf.d/default.conf:</p>
  
  <pre><code>upstream php-upstream {
      server php-fpm:9000;
  }
  </code></pre>
  
  <p>docker-compose.yml:</p>
  
  <pre><code>version: '3'
  
  services:
    database:
      build:
        context: ./database
      environment:
        - MYSQL_DATABASE=${DATABASE_NAME}
        - MYSQL_USER=${DATABASE_USER}
        - MYSQL_PASSWORD=${DATABASE_PASSWORD}
        - MYSQL_ROOT_PASSWORD=${DATABASE_ROOT_PASSWORD}
      ports:
        - "3306:3306"
      volumes:
        - ./database/init.sql:/docker-entrypoint-initdb.d/init.sql
        - ./database/data:/var/lib/mysql
  
    php-fpm:
      build:
        context: ./php-fpm
      depends_on:
        - database
      environment:
        - TIMEZONE=Europe/Tallinn
        - APP_ENV=${APP_ENV}
        - APP_SECRET=${APP_SECRET}
        - DATABASE_URL=mysql://${DATABASE_USER}:${DATABASE_PASSWORD}@database:3306/${DATABASE_NAME}?serverVersion=5.7
      volumes:
        - ../src:/var/www
  
    nginx:
      build:
        context: ./nginx
      volumes:
        - ../src:/var/www
        - ./nginx/nginx.conf:/etc/nginx/nginx.conf
        - ./nginx/sites/:/etc/nginx/sites-available
        - ./nginx/conf.d/:/etc/nginx/conf.d
        - ./logs:/var/log
      depends_on:
        - php-fpm
      ports:
        - "80:80"
        - "443:443"
  </code></pre>