fFathead
fFathead

Reputation: 51

Nginx - PHP-FPM 7.1 Docker Containers, long delay for response when accessing PHP file in sub-directory

I've been trying to resolve this for a day now, and it has beaten me.

Here's the setup:

Nginx in one docker container, php-fpm 7.1 in another docker container. Containers both have access to the same volume for files.

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.

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.

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.

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.

What is causing that 40s delay to that first repsonse only when the requested file is in a sub-directory?

Any help gratefully received.

Config files:

Docker compose

 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

Nginx Doxkerfile

FROM nginx:alpine

RUN mkdir -p /var/www

RUN set -x \
    && addgroup -g 82 -S www-data \
    && 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 {} +

PHP-FPM Dockerfile

FROM php:7.1-fpm-jessie

RUN apt-get update

RUN apt-get install -y \
        libfreetype6-dev \
        libjpeg62-turbo-dev \
        libmcrypt-dev \
        libpng12-dev \
    && docker-php-ext-install -j$(nproc) iconv pdo pdo_mysql zip mysqli \
    && docker-php-ext-configure gd \
        --with-freetype-dir=/usr/include/ \
        --with-jpeg-dir=/usr/include/ \
    && 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 {} +

Nginx conf

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;
    }
}

PHP ini additions:

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"

Upvotes: 3

Views: 2437

Answers (1)

Mehmet
Mehmet

Reputation: 180

Use for nginx & php-fpm containers in docker-compose file

/home/user/websites/test:/var/www:cached

Upvotes: 2

Related Questions