在 docker 上找不到 php-fpm 狀態頁面

在 docker 上找不到 php-fpm 狀態頁面

我有兩個用於 php-fpm 和 nginx 的 docker 容器,我使用 docker-compose.yml 檔案運行它,但我嘗試設定 php-fpm 的狀態頁面,但沒有找到。

我訪問http://localhost/狀態url 並顯示檔案未找到訊息。

我嘗試了太多的配置,但它不起作用。

我的 direcoty 樹是:

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

相關內容