带有dockerized PHP-FPM的502 Bad Gateway

时间:2018-11-14 13:38:15

标签: php docker nginx dockerfile

我正在尝试将我的PHP-FPM安装替换为docker容器。 我可以构建一个容器并启动FPM服务(127.0.0.1:9000)。

但是,当我在nginx中输入连接时,出现错误的网关(502)错误。 可能是什么原因?

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

构建并运行

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设置

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;

0 个答案:

没有答案