我有两个用于 php-fpm 和 nginx 的 docker 容器,我使用 docker-compose.yml 文件运行它,但我尝试设置我的 php-fpm 的状态页面但未找到。
我可以http://localhost/状态url 并显示文件未找到消息。
我尝试了太多配置,但不起作用。
我的目录树是:
C:.
│ docker-compose.yml
│
├───app
│ index.php
│
├───fpmConf
│ www.conf
│
├───nginxConf
│ default.conf
│
└───phpConf
php.ini
我的 docker-compose.yml 文件是:
version: '3'
services:
php:
image: php:7.2-fpm
container_name: php_app
restart: always
environment:
TZ: America/Mexico_City
ports:
- 9000:9000
volumes:
- ./app:/var/www/html
- ./phpConf/php.ini:/usr/local/etc/php/conf.d/custom.ini
tty: true
nginx:
image: nginx:latest
container_name: nginx_proxy
restart: always
environment:
TZ: America/Mexico_City
ports:
- 80:80
links:
- php
volumes:
- ./app:/var/www/html
- ./nginxConf:/etc/nginx/conf.d
- ./fpmConf/www.conf:/etc/php-fpm.d/www.conf
depends_on:
- php
tty: true
我的 www.conf 文件是:
user = www
listen = php:9000
pm = ondemand
pm.max_children = 50
pm.max_requests = 500
pm.process_idle_timeout = 10s
pm.status_path = /status
ping.path = /ping
slowlog = /data/logs/php-fpm-slow.log
request_slowlog_timeout = 60
catch_workers_output = yes
env[TMPDIR] = /data/tmp/php
include = /data/conf/php-fpm-www-*.conf
我的 default.conf 文件是:
upstream php-upstream {
server php:9000;
}
server {
server_tokens off;
charset utf-8;
client_max_body_size 128M;
proxy_buffer_size 128k;
proxy_buffers 4 256k;
proxy_busy_buffers_size 256k;
listen 80;
server_name localhost;
# set caching header for static files
location ~* \.(jpg|jpeg|gif|png|css|js|ico|svg|ttf|webp)$ {
access_log off;
log_not_found off;
expires 30d;
}
root /var/www/html;
index index.php;
location / {
try_files $uri $uri/ /index.php$is_args$args;
location ~ \.php$ {
fastcgi_split_path_info ^(.+?\.php)(/.*)$;
if (!-f $document_root$fastcgi_script_name) {
return 404;
}
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_path_info;
fastcgi_param PATH_TRANSLATED $document_root$fastcgi_path_info;
fastcgi_buffers 16 16k;
fastcgi_buffer_size 32k;
fastcgi_connect_timeout 300;
fastcgi_send_timeout 300;
fastcgi_read_timeout 300;
fastcgi_pass php:9000;
fastcgi_index index.php;
fastcgi_pass_header Set-Cookie;
fastcgi_pass_header Cookie;
fastcgi_ignore_headers Cache-Control Expires Set-Cookie;
}
}
location /status {
access_log off;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_pass php-upstream;
fastcgi_index status.html;
}
}
我的 php.ini 文件是:
date.timezone = "America/Mexico_City"
default_charset = "utf-8";
mbstring.internal_encoding=utf-8;
mbstring.http_output=UTF-8;
mbstring.encoding_translation=On;
session.use_cookies = 1
session.name = PHPSESSID
session.cookie_lifetime = 0
session.cookie_path = /
session.cookie_domain = alocalhost
session.serialize_handler = php
session.gc_maxlifetime = 86400
max_input_vars = 1000000
答案1
我解决了从容器中将 www.conf 文件复制到我的主机的问题:
docker cp -a php_app:/usr/local/etc/php-fpm.d/www.conf ./www.conf
然后我取消注释此行并与 docker 共享这些新的 www.conf 文件:
pm.status_path = /status
这是我的新 docker-compose.yml,其中包含带有 www.conf 的新卷./status/www.conf:/usr/local/etc/php-fpm.d/www.conf:
version: '3'
services:
php:
image: php:7.2-fpm
container_name: php_app
restart: always
environment:
TZ: America/Mexico_City
ports:
- 9000:9000
volumes:
- ./app:/var/www/html
- ./phpConf/php.ini:/usr/local/etc/php/conf.d/custom.ini
- ./status/www.conf:/usr/local/etc/php-fpm.d/www.conf
tty: true
nginx:
image: nginx:latest
container_name: nginx_proxy
restart: always
environment:
TZ: America/Mexico_City
ports:
- 80:80
links:
- php
volumes:
- ./app:/var/www/html
- ./nginxConf:/etc/nginx/conf.d
- ./fpmConf/www.conf:/etc/php-fpm.d/www.conf
depends_on:
- php
tty: true