title: Nginx - PHP-FPM 7.1 Docker Containers, long delay for response when accessing PHP file in sub-directory
body: <p>I've been trying to resolve this for a day now, and it has beaten me.</p>
  
  <p>Here's the setup:</p>
  
  <p>Nginx in one docker container, php-fpm 7.1 in another docker container.  Containers both have access to the same volume for files.  </p>
  
  <p>Communication is working, and it displays a phpinfo file with no problem, nice and quick, with the phpinfo file in the root directory, and also in a sub-directory.</p>
  
  <p>Copy the application files to the server.
  Files in the root directory are returned quickly, no delay.
  Any access to files in a sub-directory have a 40-50 second delay before anything happens, though are processed correctly when finally loaded.</p>
  
  <p>I can see the php-fpm process being created to handle the request, but it doesn't seem to do anything for 40-50s or so.</p>
  
  <p>The application in question is Prestahop (not yet installed, so it is trying to run the installation process), so it's not an app issue.</p>
  
  <p>What is causing that 40s delay to that first repsonse only when the requested file is in a sub-directory?</p>
  
  <p>Any help gratefully received.</p>
  
  <p>Config files:</p>
  
  <p>Docker compose</p>
  
  <pre><code> version: '2'
  services:
      nginx_test:
          image: roja45/nginx 
          working_dir: /var/www
          container_name: nginx_test
          environment:
              - WORKING_DIR=/var/www
          volumes:
              - /home/user/websites/test:/var/www
              - /home/user/docker/nginx/test.conf:/etc/nginx/conf.d/default.conf:ro
          ports:
              - "80:80"
          networks:
              - nginx-proxy
      php_test:
          image: roja45/php-fpm:7.1
          container_name: php_test
          volumes:
              - /home/user/websites/test:/var/www
              - /home/nigel/docker/php-fpm/php-roja45-dev.ini:/usr/local/etc/php/conf.d/php-roja45-dev.ini
          ports: 
              - "9000:9000"
          networks:
              - nginx-proxy
  networks:
      nginx-proxy:
          external:
              name: nginx-proxy
  volumes:
      roja45-database:
          driver: local
  </code></pre>
  
  <p>Nginx Doxkerfile</p>
  
  <pre><code>FROM nginx:alpine
  
  RUN mkdir -p /var/www
  
  RUN set -x \
      &amp;&amp; addgroup -g 82 -S www-data \
      &amp;&amp; adduser -u 82 -D -S -G www-data www-data
  
  RUN chown -R www-data:www-data /var/www
  RUN chmod u+rwx,g+rx,o+rx /var/www
  RUN find /var/www -type d -exec chmod 755 {} +
  RUN find /var/www -type f -exec chmod 644 {} +
  </code></pre>
  
  <p>PHP-FPM Dockerfile</p>
  
  <pre><code>FROM php:7.1-fpm-jessie
  
  RUN apt-get update
  
  RUN apt-get install -y \
          libfreetype6-dev \
          libjpeg62-turbo-dev \
          libmcrypt-dev \
          libpng12-dev \
      &amp;&amp; docker-php-ext-install -j$(nproc) iconv pdo pdo_mysql zip mysqli \
      &amp;&amp; docker-php-ext-configure gd \
          --with-freetype-dir=/usr/include/ \
          --with-jpeg-dir=/usr/include/ \
      &amp;&amp; docker-php-ext-install -j$(nproc) gd
  
  RUN chown -R www-data:www-data /var/www
  RUN chmod u+rwx,g+rx,o+rx /var/www
  RUN find /var/www -type d -exec chmod 755 {} +
  RUN find /var/www -type f -exec chmod 644 {} +
  </code></pre>
  
  <p>Nginx conf</p>
  
  <pre><code>server {
      listen       80;
  
      server_name  server_name;
  
      access_log  /var/log/nginx/access.log  main;
      error_log  /var/log/nginx/error.log  debug;
  
      index index.php index.html;
  
      charset utf-8;
  
      root   /var/www;
  
      error_page 404 /error404.html;
      error_page 500 /error500.html;
  
  
      location / {
          try_files $uri $uri/ /index.php;
      }
  
      location ~ ^/.+\.php(/|$) {
          fastcgi_split_path_info ^(.+.php)(/.*)$;
          try_files $uri =404;
          include /etc/nginx/fastcgi_params;
          fastcgi_keep_conn on;
          fastcgi_pass php_test:9000;
          fastcgi_index index.php;
          fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
      }
  }
  </code></pre>
  
  <p>PHP ini additions:</p>
  
  <pre><code>file_uploads = On
  memory_limit = 256M
  upload_max_filesize = 64M
  post_max_size = 64M
  max_execution_time = 30
  request_terminate_timeout = 30
  log_errors=on
  error_log = /var/www/error_log
  max_input_vars = 10000
  short_open_tag=off
  date.timezone = "America/Bogota"
  </code></pre>