php-fpm 连接被对端重置
php-fpm Connection reset by peer
我正在尝试在 Docker 图像上设置 php-fpm。
这是我的 docker-compose.yml 中的服务:
wordpress-service:
build:
context: .
dockerfile: Dockerfile-wordpress
image: riffsy-web-wordpress:latest
restart: always
links:
- wordpress-mysql
depends_on:
- wordpress-mysql
expose:
- "8000"
environment:
- DB_NAME=wordpress
- DB_USER=wordpress
- DB_PASSWORD=password123
- DB_HOST=wordpress-mysql
- DB_PORT=3306
ports:
- "8000:8000"
Docker 图像使用此命令:
CMD php-fpm7.0 --fpm-config /etc/php-fpm.conf
这是我的 php-fpm 配置文件:
[global]
error_log = /dev/stderr
log_level = debug
daemonize = no
[www]
listen = 8000
listen.allowed_clients = 127.0.0.1
user = www-data
group = www-data
pm = dynamic
pm.max_children = 6
pm.start_servers = 2
pm.min_spare_servers = 1
pm.max_spare_servers = 4
pm.max_requests = 500
request_terminate_timeout = 120s
catch_workers_output = yes
我设置了 listen.allowed_clients = 127.0.0.1
因为否则我会收到连接被拒绝的消息;最终我需要 php-fpm 来接受来自任何 IP 的连接,因为我不知道我的 Nginx 图像将具有什么 IP,而且这并不重要,因为我的 php-fpm 图像赢了'公开连接到互联网。
我 运行 docker exec
登录 运行 图像和 运行 wget
测试服务器:
root@428d78fd58df:/srv# wget 127.0.0.1:8000
--2016-09-12 07:55:13-- http://127.0.0.1:8000/
Connecting to 127.0.0.1:8000... connected.
HTTP request sent, awaiting response... Read error (Connection reset by peer) in headers.
Retrying.
--2016-09-12 07:55:14-- (try: 2) http://127.0.0.1:8000/
Connecting to 127.0.0.1:8000... connected.
HTTP request sent, awaiting response... Read error (Connection reset by peer) in headers.
Retrying.
--2016-09-12 07:55:16-- (try: 3) http://127.0.0.1:8000/
Connecting to 127.0.0.1:8000... connected.
HTTP request sent, awaiting response... Read error (Connection reset by peer) in headers.
Retrying.
^C
除了以下内容,控制台没有显示任何输出:
wordpress-service_1 | [12-Sep-2016 08:01:09.757039] DEBUG: pid 5, fpm_pctl_perform_idle_server_maintenance(), line 379: [pool www] currently 0 active children, 2 spare children, 2 running children. Spawning rate 1
问题是php-fpm没有使用http协议,它使用fastcgi。连接它的唯一方法是将 Nginx 设置为使用 fastcgi。
我正在尝试在 Docker 图像上设置 php-fpm。
这是我的 docker-compose.yml 中的服务:
wordpress-service:
build:
context: .
dockerfile: Dockerfile-wordpress
image: riffsy-web-wordpress:latest
restart: always
links:
- wordpress-mysql
depends_on:
- wordpress-mysql
expose:
- "8000"
environment:
- DB_NAME=wordpress
- DB_USER=wordpress
- DB_PASSWORD=password123
- DB_HOST=wordpress-mysql
- DB_PORT=3306
ports:
- "8000:8000"
Docker 图像使用此命令:
CMD php-fpm7.0 --fpm-config /etc/php-fpm.conf
这是我的 php-fpm 配置文件:
[global]
error_log = /dev/stderr
log_level = debug
daemonize = no
[www]
listen = 8000
listen.allowed_clients = 127.0.0.1
user = www-data
group = www-data
pm = dynamic
pm.max_children = 6
pm.start_servers = 2
pm.min_spare_servers = 1
pm.max_spare_servers = 4
pm.max_requests = 500
request_terminate_timeout = 120s
catch_workers_output = yes
我设置了 listen.allowed_clients = 127.0.0.1
因为否则我会收到连接被拒绝的消息;最终我需要 php-fpm 来接受来自任何 IP 的连接,因为我不知道我的 Nginx 图像将具有什么 IP,而且这并不重要,因为我的 php-fpm 图像赢了'公开连接到互联网。
我 运行 docker exec
登录 运行 图像和 运行 wget
测试服务器:
root@428d78fd58df:/srv# wget 127.0.0.1:8000
--2016-09-12 07:55:13-- http://127.0.0.1:8000/
Connecting to 127.0.0.1:8000... connected.
HTTP request sent, awaiting response... Read error (Connection reset by peer) in headers.
Retrying.
--2016-09-12 07:55:14-- (try: 2) http://127.0.0.1:8000/
Connecting to 127.0.0.1:8000... connected.
HTTP request sent, awaiting response... Read error (Connection reset by peer) in headers.
Retrying.
--2016-09-12 07:55:16-- (try: 3) http://127.0.0.1:8000/
Connecting to 127.0.0.1:8000... connected.
HTTP request sent, awaiting response... Read error (Connection reset by peer) in headers.
Retrying.
^C
除了以下内容,控制台没有显示任何输出:
wordpress-service_1 | [12-Sep-2016 08:01:09.757039] DEBUG: pid 5, fpm_pctl_perform_idle_server_maintenance(), line 379: [pool www] currently 0 active children, 2 spare children, 2 running children. Spawning rate 1
问题是php-fpm没有使用http协议,它使用fastcgi。连接它的唯一方法是将 Nginx 设置为使用 fastcgi。