0

I'm trying to replace my PHP-FPM installation with a docker container. I can build a container and start the FPM service (127.0.0.1:9000).

However, I get a Bad Gateway (502) error when I enter the connection in nginx. What could be the reason?

Dockerfile

FROM alpine:latest

RUN apk --update --no-cache add \
        php7 \
        php7-bcmath \
        php7-dom \
        php7-ctype \
        php7-simplexml \
        php7-session \
        php7-soap \
        php7-tokenizer \
        php7-xml \
        php7-xmlreader \
        php7-xmlwriter \
        php7-zip \
    && rm -rf /var/cache/apk/*

#COPY php.ini /etc/php7/conf.d/50-setting.ini
COPY php-fpm.conf /etc/php7/php-fpm.conf

EXPOSE 9000

CMD ["php-fpm7", "-F"]

php-fpm.conf

[global]
error_log = /dev/stderr

[default]
listen = 127.0.0.1:9000
pm = dynamic
pm.max_children = 10
pm.start_servers = 3
pm.min_spare_servers = 2
pm.max_spare_servers = 4
pm.max_requests = 400

Building and running

docker build -t php-fpm .
docker run --user="$(id -u www-data)" --name=php-fpm --rm -it -p 127.0.0.1:9000:9000 php-fpm:latest

[14-Nov-2018 13:35:23] NOTICE: fpm is running, pid 1
[14-Nov-2018 13:35:23] NOTICE: ready to handle connections

NGINX PHP Settings

include /etc/nginx/fastcgi_params;
fastcgi_intercept_errors on;
fastcgi_pass 127.0.0.1:9000;
fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
fastcgi_param  PATH_INFO        $fastcgi_path_info;
fastcgi_buffers 16 16k;
fastcgi_buffer_size 32k;

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.