Docker化PHP-FPM 9000端口状态无法通过TCP对接php-fpm_exporter求助
PHP-FPM 9000端口暴露与hipages/php-fpm-exporter连接问题解决
核心问题说明
你遇到的<ip>:9000/status连接被拒,本质是PHP-FPM的9000端口是FastCGI协议端口,并非HTTP端口,浏览器发送的HTTP请求无法被PHP-FPM解析;而exporter要通过TCP连接采集,需确保端口正确暴露且使用对应协议的采集方式。
解决方案
提供两种可行方案,按需选择:
方案一:直接通过FastCGI端口(9000)采集
1. 配置ECS容器端口映射
在ECS任务定义中,为PHP-FPM容器添加端口映射规则:将容器内的9000端口映射到ECS主机的任意可用端口(比如保留9000)。同时更新ECS服务的安全组,允许exporter所在服务器的IP访问该主机端口。
2. 验证PHP-FPM监听状态
进入PHP-FPM容器,执行命令确认监听地址:
netstat -tulpn | grep php-fpm
需确保输出包含0.0.0.0:9000,确认PHP-FPM监听所有网卡而非仅本地回环。
3. 配置exporter连接参数
启动exporter时,使用FastCGI模式的采集地址:
./php-fpm-exporter --phpfpm.scrape-uri=tcp://<ECS主机IP>:<映射的9000端口>/status
方案二:通过Nginx代理的HTTP接口采集(更安全)
无需暴露FastCGI端口,利用已有的Nginx代理/status接口:
1. 确认Nginx配置有效性
你的default.conf中已正确配置/status的FastCGI转发,且<ip>/status可正常访问,此接口直接可用。
2. 配置exporter使用HTTP模式
启动exporter时指定HTTP采集地址(若Nginx强制HTTPS则用HTTPS地址):
# HTTP模式 ./php-fpm-exporter --phpfpm.scrape-uri=http://<ECS主机IP>/status # HTTPS模式(适配你的HTTP转HTTPS规则) ./php-fpm-exporter --phpfpm.scrape-uri=https://<ECS主机IP>/status
关键注意事项
- 禁止用浏览器直接访问
ip:9000/status:9000端口仅支持FastCGI协议,不兼容HTTP请求,必然失败。 - ECS安全组需放行对应端口:方案一放行映射后的9000端口;方案二放行80/443端口。
- 若ECS主机有防火墙,需同步放行对应端口的入站流量。
你的现有配置文件
www.conf
[pool] listen = 0.0.0.0:9000 ... pm.status_path = /status
default.conf
server { listen 80 default_server; listen [::]:80 default_server; server_name _; root /var/www/html; if ($http_x_forwarded_proto = 'http') { return 301 https://$host$request_uri; } index index.php index.html index.htm default.html default.htm; location /_upload/s3/ { try_files $uri $uri/ /_upload/s3/get.php?$args; } error_page 500 /errors/500.php; error_page 404 /errors/404.php; error_page 403 /errors/perm.php; autoindex off; location ~ [^/]\.php(/|$) { if (!-f $document_root$fastcgi_script_name) { return 404; } fastcgi_index index.php; include /etc/nginx/fastcgi_params; fastcgi_intercept_errors on; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; fastcgi_pass 127.0.0.1:9000; fastcgi_buffers 16 16k; fastcgi_buffer_size 32k; proxy_connect_timeout 600; proxy_send_timeout 600; proxy_read_timeout 600; fastcgi_send_timeout 600; fastcgi_read_timeout 600; } location /v2 { try_files $uri $uri/ /v2/index.html; } location /status { fastcgi_pass localhost:9000; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params; } }
内容的提问来源于stack exchange,提问作者juan ferreira
相关产品推荐
相关产品推荐

